var KOC = require("koc.common.utils");
var QueryString = require("querystring");

var Config = require("../../config.js");
var CommonUtils = require("../common-utils");
var StateModel = require("../../controllers/statemodel");

var Redis_Helper = KOC.RedisHelper.Init(Config.Redis.ConnConfig);
var Mysql_Helper = KOC.MysqlHelper.Init(Config.Mysql.ConnConfig, Redis_Helper[Config.Redis.DB.Cache], true);

var DAL_Factory;

module.exports = DAL_Factory = {
  Common: require("./db-common").Init(Mysql_Helper, Config.Mysql.DB.Common),
  User: require("./db-user").Init(Mysql_Helper, Config.Mysql.DB.User),
  Report: require("./db-report").Init(Mysql_Helper, Config.Mysql.DB.Report),
  Log: require("./db-log").Init(Mysql_Helper, Config.Mysql.DB.Log),
  RedisCommon: require("./redis-common").Init(Redis_Helper[Config.Redis.DB.Common]),
  RedisRoom: require("./redis-room").Init(Redis_Helper[Config.Redis.DB.Room]),
  Business: {
    //region DB.User
    //region User_StateData:取得用户状态
    User_StateData: function (User_ID, callback) {
      var _StateData = StateModel.New();
      KOC.Async.series([
        //读取用户信息
        function (callback) {
          DAL_Factory.User.User_Info.Info(User_ID, function (retValue) {
            if (retValue.hasError) {
              callback(retValue);
              return;
            }
            if (retValue.returnObject.Status != 0) {
              retValue.hasError = true;
              retValue.message = "此用户已被锁定,请与管理员联系.";
              callback(retValue);
              return;
            }
            _StateData.User_ID = retValue.returnObject.User_ID;
            _StateData.NickName = retValue.returnObject.NickName;
            _StateData.RealName = retValue.returnObject.RealName;
            _StateData.VIP = retValue.returnObject.VIP;
            _StateData.VIP_Expire = retValue.returnObject.VIP_Expire;
            _StateData.IsAnchor = !!retValue.returnObject.IsAnchor;
            _StateData.IsFamily = !!retValue.returnObject.IsFamily;
            _StateData.IsAdmin = !!retValue.returnObject.IsAdmin;
            _StateData.IsIDCard = retValue.returnObject.IDCard_Status == 0;
            _StateData.IsChargeFirst = !!retValue.returnObject.Charge_First;
            _StateData.Channel_ID = retValue.returnObject.Channel_ID;
            _StateData.Inviter_ID = retValue.returnObject.Inviter_ID;
            _StateData.SignUp_Anchor_ID = retValue.returnObject.SignUp_Anchor_ID;
            _StateData.SignUp_Anchor_Family_ID = retValue.returnObject.SignUp_Anchor_Family_ID;
            _StateData.SignUp_Origin = retValue.returnObject.SignUp_Origin;
            _StateData.SignUp_Date = retValue.returnObject.Create_Date;
            callback();
          });
        },
        //读取艺人信息
        function (callback) {
          if (!_StateData.IsAnchor) {
            callback();
            return;
          }
          DAL_Factory.User.User_Anchor.Info(_StateData.User_ID, function (retValue) {
            if (retValue.hasError) {
              callback(retValue);
              return;
            }
            if (retValue.returnObject.Status != 0) {
              _StateData.IsAnchor = false;
              callback();
              return;
            }
            _StateData.Anchor = {
              RoomName: retValue.returnObject.RoomName,
              RoomWelcome: retValue.returnObject.RoomWelcome,
              Family_ID: retValue.returnObject.Family_ID
            };
            callback();
          });
        },
        //读取公会管理员信息
        function (callback) {
          if (!_StateData.IsFamily) {
            callback();
            return;
          }
          DAL_Factory.User.User_Family.Info(_StateData.User_ID, function (retValue) {
            if (retValue.hasError) {
              callback(retValue);
              return;
            }
            if (retValue.returnObject.Status != 0) {
              _StateData.IsFamily = false;
              callback();
              return;
            }
            _StateData.Family = {
              IsMaster: retValue.returnObject.IsMaster,
              RightCode: retValue.returnObject.RightCode,
              Family_ID: retValue.returnObject.Family_ID
            };
            callback();
          });
        },
        //读取管理员信息
        function (callback) {
          if (!_StateData.IsAdmin) {
            callback();
            return;
          }
          DAL_Factory.User.User_Admin.Info(_StateData.User_ID, function (retValue) {
            if (retValue.hasError) {
              callback(retValue);
              return;
            }
            if (retValue.returnObject.Status != 0) {
              _StateData.IsAdmin = false;
              callback();
              return;
            }
            _StateData.Admin = {
              RealName: retValue.returnObject.RealName,
              IsMaster: retValue.returnObject.IsMaster,
              RightCode: retValue.returnObject.RightCode
            };
            callback();
          });
        }
      ], function (retValue) {
        if (retValue) {
          callback(retValue);
          return;
        }
        callback(KOC.ReturnValue.New({
          returnObject: _StateData
        }));
      });
    },
    //endregion
    //region User_SignIn:用户注册
    User_SignIn: function (parm, callback) {
      parm = KOC.Lodash.extend({
        Channel_ID: "",
        Inviter_ID: "",
        Room_ID: "",
        Phone: "",
        PhoneCode: "",
        Password: "",
        NickName: "",
        SignUp_Origin: -1,
        SignUp_Url: "",
        Create_IP: ""
      }, parm);
      parm.Inviter_ID = KOC.StringUtils.ToInt(parm.Inviter_ID, -1);
      parm.Room_ID = KOC.StringUtils.ToInt(parm.Room_ID, -1);
      parm.SignUp_Origin = KOC.StringUtils.ToInt(parm.SignUp_Origin, -1);
      parm.NickName = parm.NickName ? parm.NickName.replace(/ /g, "").replace(/　/g, "") : null;
      KOC.Async.series([
        //验证手机验证码
        function (callback) {
          DAL_Factory.RedisCommon.PhoneAuthCode.Check(parm.Phone, parm.PhoneCode, function (retValue) {
            if (retValue.hasError) {
              callback(retValue);
              return;
            }
            callback();
          });
        },
        //验证用户昵称
        function (callback) {
          CommonUtils.User.NickName.fnBuildVerify(parm.NickName, function (retValue) {
            parm.NickName = retValue.returnObject;
            callback();
          });
        },
        //验证用户昵称
        function (callback) {
          KOC.Async.forever(function (callback) {
            DAL_Factory.User.User_Info.Info_NickName(parm.NickName, function (retValue) {
              if (retValue.hasError) {
                callback(retValue);
                return;
              }
              if (!retValue.returnObject) {
                callback(true);
                return;
              }
              parm.NickName = CommonUtils.User.NickName.fnBuild();
              callback();
            });
          }, function (retValue) {
            if (retValue === true) {
              callback();
              return;
            }
            callback(retValue);
          });
        },
        //验证邀请用户ID
        function (callback) {
          if (!parm.Inviter_ID || parm.Inviter_ID < 0) {
            callback();
            return;
          }
          DAL_Factory.User.User_Info.Info(parm.Inviter_ID, function (retValue) {
            if (retValue.hasError) {
              callback(retValue);
              return;
            }
            if (!retValue.returnObject) {
              retValue.hasError = true;
              retValue.message = "邀请人ID不存在";
              callback(retValue);
              return;
            }
            parm.Inviter_NickName = retValue.returnObject.NickName;
            callback();
          });
        },
        //获取注册所在的直播间的艺人的公会ID
        function (callback) {
          if (parm.Room_ID <= 0) {
            callback();
            return;
          }
          DAL_Factory.User.User_Anchor.Info(parm.Room_ID, function (retValue) {
            if (retValue.hasError) {
              callback(retValue);
              return;
            }
            if (!retValue.returnObject) {
              retValue.hasError = true;
              retValue.message = "无此艺人信息";
              callback(retValue);
              return;
            }
            parm.Family_ID = retValue.returnObject.Family_ID ? retValue.returnObject.Family_ID : -1;
            callback();
          });
        },
        //写入用户信息
        function (callback) {
          DAL_Factory.User.User_Info.Insert({
            Channel_ID: parm.Channel_ID,
            Inviter_ID: parm.Inviter_ID,
            Inviter_NickName: parm.Inviter_NickName,
            Room_ID: parm.Room_ID,
            Family_ID: parm.Family_ID,
            Password: parm.Password,
            NickName: parm.NickName,
            Phone: parm.Phone,
            SignUp_Origin: parm.SignUp_Origin,
            SignUp_Url: parm.SignUp_Url,
            Create_IP: parm.Create_IP
          }, function (retValue) {
            if (retValue.hasError) {
              retValue.errorCode = 999;
              retValue.message = "用户名已存在";
              callback(retValue);
              return;
            }
            parm.User_ID = KOC.StringUtils.ToInt(retValue.GetValue("insertId"), -1);
            callback();
          });
        },
        //邀请人数修改
        function (callback) {
          if (!parm.Inviter_ID || parm.Inviter_ID < 0) {
            callback();
            return;
          }
          DAL_Factory.User.User_Info.Update_InviteCount(parm.Inviter_ID, function (retValue) {
            if (retValue.hasError) {
              callback(retValue);
              return;
            }
            if (!retValue.returnObject) {
              retValue.hasError = true;
              retValue.message = "邀请人ID不存在";
              callback(retValue);
              return;
            }
            parm.Inviter_NickName = retValue.returnObject.Inviter_NickName;
            callback();
          });
        },
        //读取用户个人信息
        function (callback) {
          DAL_Factory.User.User_Info.Info(parm.User_ID, function (retValue) {
            if (retValue.hasError) {
              callback(retValue);
              return;
            }
            if (!retValue.returnObject) {
              retValue.hasError = true;
              retValue.message = "用户不存在";
              callback(retValue);
              return;
            }
            parm.User_NickName = retValue.returnObject.NickName;
            parm.User_RealName = retValue.returnObject.RealName;
            callback();
          });
        },
        //任务提交
        function (callback) {
          if (!parm.Phone) {
            callback();
            return;
          }
          DAL_Factory.Business.User_Task({
            User_ID: parm.User_ID,
            User_NickName: parm.User_NickName,
            User_RealName: parm.User_RealName,
            Task_ID: 1005,
            Task_Progress: 1,
            Create_IP: parm.Create_IP
          }, function () {
            callback();
          });
        },
        //用户登陆
        function (callback) {
          DAL_Factory.Business.User_Login({
            LoginName: parm.Phone,
            Password: parm.Password,
            SignIn_Origin: 0,
            SignIn_Type: 2,
            Create_IP: parm.Create_IP
          }, function (retValue) {
            if (retValue.hasError) {
              callback(retValue);
              return;
            }
            parm.StateData = retValue.returnObject;
            callback();
          });
        },
        //更新艺人热度
        function (callback) {
          if (parm.Room_ID <= 0) {
            callback();
            return;
          }
          DAL_Factory.Business.User_AnchorHot({
            Type: "SignUp",
            Value: CommonUtils.Anchor.Hot.SignUp,
            User_ID: parm.Room_ID
          }, function () {
            callback();
          });
        }
      ], function (retValue) {
        if (retValue) {
          callback(retValue);
          return;
        }
        callback(KOC.ReturnValue.New({
          returnObject: parm.StateData
        }));
      });
    },
    //endregion
    // region User_PasswordUpdate:用户修改密码
    User_PasswordUpdate: function (parm, callback) {
      parm = KOC.Lodash.extend({
        User_ID: null,
        Password: null,
        Password_Old: null,
        Phone: null,
        Type: null //修改密码类型，true-验证旧密码,传User_ID，false-不验证旧密码,传Phone
      }, parm);
      KOC.Async.series([
        //读取用户个人信息
        function (callback) {
          if (!parm.Type) {
            callback();
            return;
          }
          DAL_Factory.User.User_Info.Info(parm.User_ID, function (retValue) {
            if (retValue.hasError) {
              callback(retValue);
              return;
            }
            if (!retValue.returnObject) {
              retValue.hasError = true;
              retValue.message = "用户不存在";
              callback(retValue);
              return;
            }
            if (!retValue.returnObject.Password) {
              retValue.hasError = true;
              retValue.message = "用户没有密码";
              callback(retValue);
              return;
            }
            if (KOC.StringUtils.MD5(parm.Password_Old + retValue.returnObject.PasswordKey) != retValue.returnObject.Password) {
              retValue.hasError = true;
              retValue.message = "原密码输入有误";
              callback(retValue);
              return;
            }
            callback();
          });
        },
        //读取用户个人信息
        function (callback) {
          if (parm.Type) {
            callback();
            return;
          }
          DAL_Factory.User.User_Info.Info_Phone(parm.Phone, function (retValue) {
            if (retValue.hasError) {
              callback(retValue);
              return;
            }
            if (!retValue.returnObject) {
              retValue.hasError = true;
              retValue.message = "用户不存在";
              callback(retValue);
              return;
            }
            parm.User_ID = retValue.returnObject.User_ID;
            callback();
          });
        },
        //修改密码
        function (callback) {
          DAL_Factory.User.User_Info.Update_Password(null, {
            User_ID: parm.User_ID,
            Password: parm.Password
          }, function (retValue) {
            if (retValue.hasError) {
              callback(retValue);
              return;
            }
            if (retValue.returnObject !== 1) {
              retValue.hasError = true;
              retValue.message = "密码错误出错(影响" + retValue.returnObject + "行)";
              callback(retValue);
              return;
            }
            callback();
          });
        }
      ], function (retValue) {
        if (retValue) {
          console.log("用户修改密码失败:", retValue, parm);
          callback(retValue);
          return;
        }
        callback(KOC.ReturnValue.New());
      });
    },
    //endregion
    //region User_PasswordReset:用户重置密码(找回密码)
    User_PasswordReset: function (parm, callback) {
      parm = KOC.Lodash.extend({
        User_ID: null
      }, parm);
      //生成新密码
      parm.Password = KOC.Lodash.random(100000, 999999).toString();
      //修改密码
      DAL_Factory.User.User_Info.Update_Password(null, {
        User_ID: parm.User_ID,
        Password: KOC.StringUtils.MD5(parm.Password)
      }, function (retValue) {
        if (retValue.hasError) {
          callback(retValue);
          return;
        }
        if (retValue.returnObject !== 1) {
          retValue.hasError = true;
          retValue.message = "密码错误出错(影响" + retValue.returnObject + "行)";
          callback(retValue);
          return;
        }
        callback(KOC.ReturnValue.New({
          returnObject: parm
        }));
      });
    },
    //endregion
    //region User_OAuthQQ:QQ绑定
    User_OAuthQQ: function (parm, callback) {
      parm = KOC.Lodash.extend({
        User_ID: -1,
        OAuth_QQ_ID: null,
        OAuth_QQ_Token: null,
        OAuth_QQ_ExpiresIn: null,
        OAuth_QQ_RefreshToken: null,
        NickName: null,
        Sex: null,
        Channel_ID: null,
        Inviter_ID: null,
        Room_ID: null,
        SignUp_Origin: -1,
        SignUp_Url: "",
        Create_IP: ""
      }, parm);
      parm.User_ID = KOC.StringUtils.ToInt(parm.User_ID, -1);
      parm.NickName = parm.NickName ? parm.NickName.replace(/ /g, "").replace(/　/g, "") : null;
      parm.SignUp_Origin = KOC.StringUtils.ToInt(parm.SignUp_Origin, -1);
      var _Type = "SignUp"; //SignUp:注册 Bind:绑定
      KOC.Async.series([
        //读取用户信息(User_ID)
        function (callback) {
          if (parm.User_ID <= 0) {
            callback();
            return;
          }
          DAL_Factory.User.User_Info.Info(parm.User_ID, function (retValue) {
            if (retValue.hasError) {
              callback(retValue);
              return;
            }
            if (!retValue.returnObject) {
              retValue.hasError = true;
              retValue.message = "用户ID错误,请核实";
              callback(retValue);
              return;
            }
            _Type = retValue.returnObject.OAuth_QQ_ID == parm.OAuth_QQ_ID ? "" : "Bind";
            callback();
          });
        },
        //读取用户信息(OAuth_QQ_ID)
        function (callback) {
          if (!_Type) {
            callback();
            return;
          }
          DAL_Factory.User.User_Info.Info_OAuthQQ(parm.OAuth_QQ_ID, function (retValue) {
            if (retValue.hasError) {
              callback(retValue);
              return;
            }
            if (retValue.returnObject && parm.User_ID > 0) {
              retValue.hasError = true;
              retValue.message = "此QQ号已被其它帐号绑定,如需绑定到此帐号请先登录原帐号解除绑定";
              callback(retValue);
              return;
            }
            if (retValue.returnObject) {
              parm.User_ID = retValue.returnObject.User_ID;
              _Type = "";
            }
            callback();
          });
        },
        //验证用户昵称
        function (callback) {
          if (_Type != "SignUp") {
            callback();
            return;
          }
          CommonUtils.User.NickName.fnBuildVerify(parm.NickName, function (retValue) {
            parm.NickName = retValue.returnObject;
            callback();
          });
        },
        //验证用户昵称
        function (callback) {
          if (_Type != "SignUp") {
            callback();
            return;
          }
          KOC.Async.forever(function (callback) {
            DAL_Factory.User.User_Info.Info_NickName(parm.NickName, function (retValue) {
              if (retValue.hasError) {
                callback(retValue);
                return;
              }
              if (!retValue.returnObject) {
                callback(true);
                return;
              }
              parm.NickName = CommonUtils.User.NickName.fnBuild();
              callback();
            });
          }, function (retValue) {
            if (retValue === true) {
              callback();
              return;
            }
            callback(retValue);
          });
        },
        //验证邀请用户ID
        function (callback) {
          if (_Type != "SignUp") {
            callback();
            return;
          }
          if (!parm.Inviter_ID || parm.Inviter_ID < 0) {
            callback();
            return;
          }
          DAL_Factory.User.User_Info.Info(parm.Inviter_ID, function (retValue) {
            if (retValue.hasError) {
              callback(retValue);
              return;
            }
            if (!retValue.returnObject) {
              retValue.hasError = true;
              retValue.message = "邀请人ID不存在";
              callback(retValue);
              return;
            }
            parm.Inviter_NickName = retValue.returnObject.NickName;
            callback();
          });
        },
        //获取注册所在的直播间的艺人的公会ID
        function (callback) {
          if (_Type != "SignUp") {
            callback();
            return;
          }
          if (!parm.Room_ID || parm.Room_ID < 0) {
            callback();
            return;
          }
          DAL_Factory.User.User_Anchor.Info(parm.Room_ID, function (retValue) {
            if (retValue.hasError) {
              callback(retValue);
              return;
            }
            if (!retValue.returnObject) {
              retValue.hasError = true;
              retValue.message = "无此艺人信息";
              callback(retValue);
              return;
            }
            parm.Family_ID = retValue.returnObject.Family_ID ? retValue.returnObject.Family_ID : -1;
            callback();
          });
        },
        //写入新用户
        function (callback) {
          if (_Type != "SignUp") {
            callback();
            return;
          }
          DAL_Factory.User.User_Info.Insert_OAuthQQ({
            OAuth_QQ_ID: parm.OAuth_QQ_ID,
            OAuth_QQ_Token: parm.OAuth_QQ_Token,
            OAuth_QQ_ExpiresIn: parm.OAuth_QQ_ExpiresIn,
            OAuth_QQ_RefreshToken: parm.OAuth_QQ_RefreshToken,
            NickName: parm.NickName,
            Sex: parm.Sex,
            Channel_ID: parm.Channel_ID,
            Inviter_ID: parm.Inviter_ID,
            Inviter_NickName: parm.Inviter_NickName,
            Room_ID: parm.Room_ID,
            Family_ID: parm.Family_ID,
            SignUp_Origin: parm.SignUp_Origin,
            SignUp_Url: parm.SignUp_Url,
            Create_IP: parm.Create_IP
          }, function (retValue) {
            if (retValue.hasError) {
              callback(retValue);
              return;
            }
            parm.User_ID = KOC.StringUtils.ToInt(retValue.GetValue("insertId"), -1);
            callback();
          });
        },
        //更新艺人热度
        function (callback) {
          if (_Type != "SignUp") {
            callback();
            return;
          }
          if (!parm.Room_ID || parm.Room_ID <= 0) {
            callback();
            return;
          }
          DAL_Factory.Business.User_AnchorHot({
            Type: "SignUp",
            Value: CommonUtils.Anchor.Hot.SignUp,
            User_ID: parm.Room_ID
          }, function () {
            callback();
          });
        },
        //QQ帐号绑定
        function (callback) {
          if (_Type != "Bind") {
            callback();
            return;
          }
          DAL_Factory.User.User_Info.Update_OAuthQQ({
            User_ID: parm.User_ID,
            OAuth_QQ_ID: parm.OAuth_QQ_ID,
            OAuth_QQ_Token: parm.OAuth_QQ_Token,
            OAuth_QQ_ExpiresIn: parm.OAuth_QQ_ExpiresIn,
            OAuth_QQ_RefreshToken: parm.OAuth_QQ_RefreshToken,
            Sex: parm.Sex,
            Create_IP: parm.Create_IP
          }, function (retValue) {
            if (retValue.hasError) {
              callback(retValue);
              return;
            }
            if (retValue.returnObject !== 1) {
              retValue.hasError = true;
              retValue.message = "更新用户QQ授权信息出错，影响行(" + retValue.returnObject + ")";
              callback(retValue);
              return;
            }
            callback();
          });
        }
      ], function (retValue) {
        if (retValue) {
          callback(retValue);
          return;
        }
        callback(KOC.ReturnValue.New({
          returnObject: {
            User_ID: parm.User_ID
          }
        }));
      });
    },
    //endregion
    //region User_OAuthWeibo:Weibo绑定
    User_OAuthWeibo: function (parm, callback) {
      parm = KOC.Lodash.extend({
        User_ID: -1,
        OAuth_Weibo_ID: null,
        OAuth_Weibo_Token: null,
        OAuth_Weibo_ExpiresIn: null,
        NickName: null,
        Sex: null,
        Channel_ID: null,
        Inviter_ID: null,
        Room_ID: null,
        SignUp_Origin: -1,
        SignUp_Url: "",
        Create_IP: ""
      }, parm);
      parm.User_ID = KOC.StringUtils.ToInt(parm.User_ID, -1);
      parm.NickName = parm.NickName ? parm.NickName.replace(/ /g, "").replace(/　/g, "") : null;
      parm.SignUp_Origin = KOC.StringUtils.ToInt(parm.SignUp_Origin, -1);
      var _Type = "SignUp"; //SignUp:注册 Bind:绑定
      KOC.Async.series([
        //读取用户信息(User_ID)
        function (callback) {
          if (parm.User_ID <= 0) {
            callback();
            return;
          }
          DAL_Factory.User.User_Info.Info(parm.User_ID, function (retValue) {
            if (retValue.hasError) {
              callback(retValue);
              return;
            }
            if (!retValue.returnObject) {
              retValue.hasError = true;
              retValue.message = "用户ID错误,请核实";
              callback(retValue);
              return;
            }
            _Type = retValue.returnObject.OAuth_Weibo_ID == parm.OAuth_Weibo_ID ? "" : "Bind";
            callback();
          });
        },
        //读取用户信息(OAuth_Weibo_ID)
        function (callback) {
          if (!_Type) {
            callback();
            return;
          }
          DAL_Factory.User.User_Info.Info_OAuthWeibo(parm.OAuth_Weibo_ID, function (retValue) {
            if (retValue.hasError) {
              callback(retValue);
              return;
            }
            if (retValue.returnObject && parm.User_ID > 0) {
              retValue.hasError = true;
              retValue.message = "此Weibo号已被其它帐号绑定,如需绑定到此帐号请先登录原帐号解除绑定";
              callback(retValue);
              return;
            }
            if (retValue.returnObject) {
              parm.User_ID = retValue.returnObject.User_ID;
              _Type = "";
            }
            callback();
          });
        },
        //验证用户昵称
        function (callback) {
          if (_Type != "SignUp") {
            callback();
            return;
          }
          CommonUtils.User.NickName.fnBuildVerify(parm.NickName, function (retValue) {
            parm.NickName = retValue.returnObject;
            callback();
          });
        },
        //验证用户昵称
        function (callback) {
          if (_Type != "SignUp") {
            callback();
            return;
          }
          KOC.Async.forever(function (callback) {
            DAL_Factory.User.User_Info.Info_NickName(parm.NickName, function (retValue) {
              if (retValue.hasError) {
                callback(retValue);
                return;
              }
              if (!retValue.returnObject) {
                callback(true);
                return;
              }
              parm.NickName = CommonUtils.User.NickName.fnBuild();
              callback();
            });
          }, function (retValue) {
            if (retValue === true) {
              callback();
              return;
            }
            callback(retValue);
          });
        },
        //验证邀请用户ID
        function (callback) {
          if (_Type != "SignUp") {
            callback();
            return;
          }
          if (!parm.Inviter_ID || parm.Inviter_ID < 0) {
            callback();
            return;
          }
          DAL_Factory.User.User_Info.Info(parm.Inviter_ID, function (retValue) {
            if (retValue.hasError) {
              callback(retValue);
              return;
            }
            if (!retValue.returnObject) {
              retValue.hasError = true;
              retValue.message = "邀请人ID不存在";
              callback(retValue);
              return;
            }
            parm.Inviter_NickName = retValue.returnObject.NickName;
            callback();
          });
        },
        //获取注册所在的直播间的艺人的公会ID
        function (callback) {
          if (_Type != "SignUp") {
            callback();
            return;
          }
          if (!parm.Room_ID || parm.Room_ID < 0) {
            callback();
            return;
          }
          DAL_Factory.User.User_Anchor.Info(parm.Room_ID, function (retValue) {
            if (retValue.hasError) {
              callback(retValue);
              return;
            }
            if (!retValue.returnObject) {
              retValue.hasError = true;
              retValue.message = "无此艺人信息";
              callback(retValue);
              return;
            }
            parm.Family_ID = retValue.returnObject.Family_ID ? retValue.returnObject.Family_ID : -1;
            callback();
          });
        },
        //写入新用户
        function (callback) {
          if (_Type != "SignUp") {
            callback();
            return;
          }
          DAL_Factory.User.User_Info.Insert_OAuthWeibo({
            OAuth_Weibo_ID: parm.OAuth_Weibo_ID,
            OAuth_Weibo_Token: parm.OAuth_Weibo_Token,
            OAuth_Weibo_ExpiresIn: parm.OAuth_Weibo_ExpiresIn,
            NickName: parm.NickName,
            Sex: parm.Sex,
            Channel_ID: parm.Channel_ID,
            Inviter_ID: parm.Inviter_ID,
            Inviter_NickName: parm.Inviter_NickName,
            Room_ID: parm.Room_ID,
            Family_ID: parm.Family_ID,
            SignUp_Origin: parm.SignUp_Origin,
            SignUp_Url: parm.SignUp_Url,
            Create_IP: parm.Create_IP
          }, function (retValue) {
            if (retValue.hasError) {
              callback(retValue);
              return;
            }
            parm.User_ID = KOC.StringUtils.ToInt(retValue.GetValue("insertId"), -1);
            callback();
          });
        },
        //更新艺人热度
        function (callback) {
          if (_Type != "SignUp") {
            callback();
            return;
          }
          if (!parm.Room_ID || parm.Room_ID <= 0) {
            callback();
            return;
          }
          DAL_Factory.Business.User_AnchorHot({
            Type: "SignUp",
            Value: CommonUtils.Anchor.Hot.SignUp,
            User_ID: parm.Room_ID
          }, function () {
            callback();
          });
        },
        //Weibo帐号绑定
        function (callback) {
          if (_Type != "Bind") {
            callback();
            return;
          }
          DAL_Factory.User.User_Info.Update_OAuthWeibo({
            User_ID: parm.User_ID,
            OAuth_Weibo_ID: parm.OAuth_Weibo_ID,
            OAuth_Weibo_Token: parm.OAuth_Weibo_Token,
            OAuth_Weibo_ExpiresIn: parm.OAuth_Weibo_ExpiresIn,
            Sex: parm.Sex,
            Create_IP: parm.Create_IP
          }, function (retValue) {
            if (retValue.hasError) {
              callback(retValue);
              return;
            }
            if (retValue.returnObject !== 1) {
              retValue.hasError = true;
              retValue.message = "更新用户Weibo授权信息出错，影响行(" + retValue.returnObject + ")";
              callback(retValue);
              return;
            }
            callback();
          });
        }
      ], function (retValue) {
        if (retValue) {
          callback(retValue);
          return;
        }
        callback(KOC.ReturnValue.New({
          returnObject: {
            User_ID: parm.User_ID
          }
        }));
      });
    },
    //endregion
    //region User_OAuthWeixin:Weixin绑定
    User_OAuthWeixin: function (parm, callback) {
      parm = KOC.Lodash.extend({
        User_ID: -1,
        OAuth_Weixin_ID: null,
        OAuth_Weixin_UNIONID: null,
        OAuth_Weixin_Token: null,
        OAuth_Weixin_ExpiresIn: null,
        OAuth_Weixin_RefreshToken: null,
        NickName: null,
        Sex: null,
        Channel_ID: null,
        Inviter_ID: null,
        Room_ID: null,
        SignUp_Origin: -1,
        SignUp_Url: "",
        Create_IP: ""
      }, parm);
      parm.User_ID = KOC.StringUtils.ToInt(parm.User_ID, -1);
      parm.NickName = parm.NickName ? parm.NickName.replace(/ /g, "").replace(/　/g, "") : null;
      parm.SignUp_Origin = KOC.StringUtils.ToInt(parm.SignUp_Origin, -1);
      var _Type = "SignUp"; //SignUp:注册 Bind:绑定
      KOC.Async.series([
        //读取用户信息(User_ID)
        function (callback) {
          if (parm.User_ID <= 0) {
            callback();
            return;
          }
          DAL_Factory.User.User_Info.Info(parm.User_ID, function (retValue) {
            if (retValue.hasError) {
              callback(retValue);
              return;
            }
            if (!retValue.returnObject) {
              retValue.hasError = true;
              retValue.message = "用户ID错误,请核实";
              callback(retValue);
              return;
            }
            _Type = retValue.returnObject.OAuth_Weixin_UNIONID == parm.OAuth_Weixin_UNIONID ? "" : "Bind";
            callback();
          });
        },
        //读取用户信息(OAuth_Weixin_UNIONID)
        function (callback) {
          if (!_Type) {
            callback();
            return;
          }
          DAL_Factory.User.User_Info.Info_OAuthWeixin(parm.OAuth_Weixin_UNIONID, function (retValue) {
            if (retValue.hasError) {
              callback(retValue);
              return;
            }
            if (retValue.returnObject && parm.User_ID > 0) {
              retValue.hasError = true;
              retValue.message = "此微信号已被其它帐号绑定,如需绑定到此帐号请先登录原帐号解除绑定";
              callback(retValue);
              return;
            }
            if (retValue.returnObject) {
              parm.User_ID = retValue.returnObject.User_ID;
              _Type = "";
            }
            callback();
          });
        },
        //验证用户昵称
        function (callback) {
          if (_Type != "SignUp") {
            callback();
            return;
          }
          CommonUtils.User.NickName.fnBuildVerify(parm.NickName, function (retValue) {
            parm.NickName = retValue.returnObject;
            callback();
          });
        },
        //验证用户昵称
        function (callback) {
          if (_Type != "SignUp") {
            callback();
            return;
          }
          KOC.Async.forever(function (callback) {
            DAL_Factory.User.User_Info.Info_NickName(parm.NickName, function (retValue) {
              if (retValue.hasError) {
                callback(retValue);
                return;
              }
              if (!retValue.returnObject) {
                callback(true);
                return;
              }
              parm.NickName = CommonUtils.User.NickName.fnBuild();
              callback();
            });
          }, function (retValue) {
            if (retValue === true) {
              callback();
              return;
            }
            callback(retValue);
          });
        },
        //验证邀请用户ID
        function (callback) {
          if (_Type != "SignUp") {
            callback();
            return;
          }
          if (!parm.Inviter_ID || parm.Inviter_ID < 0) {
            callback();
            return;
          }
          DAL_Factory.User.User_Info.Info(parm.Inviter_ID, function (retValue) {
            if (retValue.hasError) {
              callback(retValue);
              return;
            }
            if (!retValue.returnObject) {
              retValue.hasError = true;
              retValue.message = "邀请人ID不存在";
              callback(retValue);
              return;
            }
            parm.Inviter_NickName = retValue.returnObject.NickName;
            callback();
          });
        },
        //获取注册所在的直播间的艺人的公会ID
        function (callback) {
          if (_Type != "SignUp") {
            callback();
            return;
          }
          if (!parm.Room_ID || parm.Room_ID < 0) {
            callback();
            return;
          }
          DAL_Factory.User.User_Anchor.Info(parm.Room_ID, function (retValue) {
            if (retValue.hasError) {
              callback(retValue);
              return;
            }
            if (!retValue.returnObject) {
              retValue.hasError = true;
              retValue.message = "无此艺人信息";
              callback(retValue);
              return;
            }
            parm.Family_ID = retValue.returnObject.Family_ID ? retValue.returnObject.Family_ID : -1;
            callback();
          });
        },
        //写入新用户
        function (callback) {
          if (_Type != "SignUp") {
            callback();
            return;
          }
          DAL_Factory.User.User_Info.Insert_OAuthWeixin({
            OAuth_Weixin_ID: parm.OAuth_Weixin_ID,
            OAuth_Weixin_UNIONID: parm.OAuth_Weixin_UNIONID,
            OAuth_Weixin_Token: parm.OAuth_Weixin_Token,
            OAuth_Weixin_ExpiresIn: parm.OAuth_Weixin_ExpiresIn,
            OAuth_Weixin_RefreshToken: parm.OAuth_Weixin_RefreshToken,
            NickName: parm.NickName,
            Sex: parm.Sex,
            Channel_ID: parm.Channel_ID,
            Inviter_ID: parm.Inviter_ID,
            Inviter_NickName: parm.Inviter_NickName,
            Room_ID: parm.Room_ID,
            Family_ID: parm.Family_ID,
            SignUp_Origin: parm.SignUp_Origin,
            SignUp_Url: parm.SignUp_Url,
            Create_IP: parm.Create_IP
          }, function (retValue) {
            if (retValue.hasError) {
              callback(retValue);
              return;
            }
            parm.User_ID = KOC.StringUtils.ToInt(retValue.GetValue("insertId"), -1);
            callback();
          });
        },
        //更新艺人热度
        function (callback) {
          if (_Type != "SignUp") {
            callback();
            return;
          }
          if (!parm.Room_ID || parm.Room_ID <= 0) {
            callback();
            return;
          }
          DAL_Factory.Business.User_AnchorHot({
            Type: "SignUp",
            Value: CommonUtils.Anchor.Hot.SignUp,
            User_ID: parm.Room_ID
          }, function () {
            callback();
          });
        },
        //Weixin帐号绑定
        function (callback) {
          if (_Type != "Bind") {
            callback();
            return;
          }
          DAL_Factory.User.User_Info.Update_OAuthWeixin({
            User_ID: parm.User_ID,
            OAuth_Weixin_ID: parm.OAuth_Weixin_ID,
            OAuth_Weixin_UNIONID: parm.OAuth_Weixin_UNIONID,
            OAuth_Weixin_Token: parm.OAuth_Weixin_Token,
            OAuth_Weixin_ExpiresIn: parm.OAuth_Weixin_ExpiresIn,
            OAuth_Weixin_RefreshToken: parm.OAuth_Weixin_RefreshToken,
            Sex: parm.Sex,
            Create_IP: parm.Create_IP
          }, function (retValue) {
            if (retValue.hasError) {
              callback(retValue);
              return;
            }
            if (retValue.returnObject !== 1) {
              retValue.hasError = true;
              retValue.message = "更新用户Weixin授权信息出错，影响行(" + retValue.returnObject + ")";
              callback(retValue);
              return;
            }
            callback();
          });
        }
      ], function (retValue) {
        if (retValue) {
          callback(retValue);
          return;
        }
        callback(KOC.ReturnValue.New({
          returnObject: {
            User_ID: parm.User_ID
          }
        }));
      });
    },
    //endregion
    //region User_OAuthPhone绑定手机
    User_OAuthPhone: function (parm, callback) {
      parm = KOC.Lodash.extend({
        User_ID: -1,
        OAuth_Phone: null,
        PhoneCode: null,
        Password: null,
        Type: null,
        Channel_ID: null,
        SignUp_Origin: -1,
        SignUp_Url: null,
        Create_IP: ""
      }, parm);
      parm.User_ID = KOC.StringUtils.ToInt(parm.User_ID, -1);
      parm.SignUp_Origin = KOC.StringUtils.ToInt(parm.SignUp_Origin, -1);
      var _Type = "SignUp"; //SignUp:注册 Bind:绑定 "":登录
      KOC.Async.series([
        //读取用户信息(User_ID)
        function (callback) {
          if (parm.Type && parm.Type == "SignUp") {
            callback();
            return;
          }
          if (parm.User_ID <= 0) {
            callback();
            return;
          }
          DAL_Factory.User.User_Info.Info(parm.User_ID, function (retValue) {
            if (retValue.hasError) {
              callback(retValue);
              return;
            }
            if (!retValue.returnObject) {
              retValue.hasError = true;
              retValue.message = "用户ID错误,请核实";
              callback(retValue);
              return;
            }
            _Type = retValue.returnObject.Phone == parm.OAuth_Phone ? "" : "Bind";
            callback();
          });
        },
        //读取用户信息(Phone)
        function (callback) {
          if (!_Type) {
            callback();
            return;
          }
          DAL_Factory.User.User_Info.Info_Phone(parm.OAuth_Phone, function (retValue) {
            if (retValue.hasError) {
              callback(retValue);
              return;
            }
            if (retValue.returnObject && parm.User_ID > 0) {
              retValue.hasError = true;
              retValue.message = "此手机号已被其它帐号绑定,如需绑定到此帐号请先登录原帐号解除绑定";
              callback(retValue);
              return;
            }
            if (retValue.returnObject && (parm.Type && parm.Type == "SignUp")) {
              retValue.hasError = true;
              retValue.message = "此手机号已经被注册";
              callback(retValue);
              return;
            }
            if (retValue.returnObject) {
              parm.User_ID = retValue.returnObject.User_ID;
              _Type = "";
            }
            callback();
          });
        },
        //验证用户昵称
        function (callback) {
          if (!(parm.Type && parm.Type == "SignUp") && _Type != "SignUp") {
            callback();
            return;
          }
          CommonUtils.User.NickName.fnBuildVerify(parm.NickName, function (retValue) {
            parm.NickName = retValue.returnObject;
            callback();
          });
        },
        //验证用户昵称
        function (callback) {
          if (!(parm.Type && parm.Type == "SignUp") && _Type != "SignUp") {
            callback();
            return;
          }
          KOC.Async.forever(function (callback) {
            DAL_Factory.User.User_Info.Info_NickName(parm.NickName, function (retValue) {
              if (retValue.hasError) {
                callback(retValue);
                return;
              }
              if (!retValue.returnObject) {
                callback(true);
                return;
              }
              parm.NickName = CommonUtils.User.NickName.fnBuild();
              callback();
            });
          }, function (retValue) {
            if (retValue === true) {
              callback();
              return;
            }
            callback(retValue);
          });
        },
        //验证手机验证码
        function (callback) {
          DAL_Factory.RedisCommon.PhoneAuthCode.Check(parm.OAuth_Phone, parm.PhoneCode, function (retValue) {
            if (retValue.hasError) {
              callback(retValue);
              return;
            }
            callback();
          });
        },
        //写入新用户
        function (callback) {
          if (!(parm.Type && parm.Type == "SignUp") && _Type != "SignUp") {
            callback();
            return;
          }
          _Type = "SignUp";
          DAL_Factory.User.User_Info.Insert_OAuthPhone({
            Phone: parm.OAuth_Phone,
            Password: parm.Password,
            NickName: parm.NickName,
            Channel_ID: parm.Channel_ID,
            SignUp_Origin: parm.SignUp_Origin,
            SignUp_Url: parm.SignUp_Url,
            Create_IP: parm.Create_IP
          }, function (retValue) {
            if (retValue.hasError) {
              callback(retValue);
              return;
            }
            parm.User_ID = KOC.StringUtils.ToInt(retValue.GetValue("insertId"), -1);
            callback();
          });
        },
        //手机帐号绑定
        function (callback) {
          if (_Type != "Bind") {
            callback();
            return;
          }
          DAL_Factory.User.User_Info.Update_Phone(null, {
            User_ID: parm.User_ID,
            Phone: parm.OAuth_Phone
          }, function (retValue) {
            if (retValue.hasError) {
              callback(retValue);
              return;
            }
            if (retValue.returnObject !== 1) {
              retValue.hasError = true;
              retValue.message = "更新用户Phone授权信息出错，影响行(" + retValue.returnObject + ")";
              callback(retValue);
              return;
            }
            callback();
          });
        },
        //更新用户密码
        function (callback) {
          if (_Type != "Bind") {
            callback();
            return;
          }
          if (!parm.Password) {
            //平台账号绑定，不修改密码
            callback();
            return;
          }
          DAL_Factory.User.User_Info.Update_Password(null, {
            Password: parm.Password,
            User_ID: parm.User_ID
          }, function (retValue) {
            if (retValue.hasError) {
              callback(retValue);
              return;
            }
            if (retValue.returnObject !== 1) {
              retValue.hasError = true;
              retValue.message = "更新用户手机号信息出错，影响行(" + retValue.returnObject + ")";
              callback(retValue);
              return;
            }
            callback();
          });
        },
        //任务提交
        function (callback) {
          if (!_Type) {
            callback();
            return;
          }
          DAL_Factory.Business.User_Task({
            User_ID: parm.User_ID,
            User_NickName: parm.NickName,
            User_RealName: "",
            Task_ID: 1005,
            Task_Progress: 1,
            Create_IP: parm.Create_IP
          }, function () {
            callback();
          });
        }
      ], function (retValue) {
        if (retValue) {
          callback(retValue);
          return;
        }
        callback(KOC.ReturnValue.New({
          returnObject: {
            User_ID: parm.User_ID
          }
        }));
      });
    },
    //endregion
    //region User_Login:用户登陆
    User_Login: function (parm, callback) {
      parm = KOC.Lodash.extend({
        User_ID: null,
        LoginName: "",
        Password: "",
        SignIn_Origin: -1, //登录来源:-1:默认,未知,来源,0-PC,100-安卓,300-IOS
        SignIn_Type: -1, //登录方式 -1:未知 1:记住 2:用户名 10:QQ 11:微信 12:微博
        Create_IP: ""
      }, parm);
      KOC.Async.series([
        //读取用户信息
        function (callback) {
          if (parm.User_ID && parm.User_ID > 0) {
            callback();
            return;
          }
          DAL_Factory.User.User_Info.Info_Login(parm.LoginName, function (retValue) {
            if (retValue.hasError) {
              callback(retValue);
              return;
            }
            if (!retValue.returnObject) {
              retValue.hasError = true;
              retValue.message = "用户名错误,请核实";
              callback(retValue);
              return;
            }
            if (KOC.StringUtils.MD5(parm.Password + retValue.returnObject.PasswordKey) != retValue.returnObject.Password) {
              retValue.hasError = true;
              retValue.message = "密码不正确";
              callback(retValue);
              return;
            }
            parm.User_ID = retValue.returnObject.User_ID;
            callback();
          });
        },
        //取得用户状态
        function (callback) {
          DAL_Factory.Business.User_StateData(parm.User_ID, function (retValue) {
            if (retValue.hasError) {
              callback(retValue);
              return;
            }
            parm.StateData = retValue.returnObject;
            parm.StateData.IsLogin = true;
            callback();
          });
        },
        //写入最后登录信息
        function (callback) {
          DAL_Factory.User.User_Info.Update_Login({
            Login_This_IP: parm.Create_IP,
            User_ID: parm.User_ID
          }, function (retValue) {
            if (retValue.hasError) {
              callback(retValue);
              return;
            }
            if (retValue.returnObject !== 1) {
              retValue.hasError = true;
              retValue.message = "写入用户登录信息出错，影响行(" + retValue.returnObject + ")";
              callback(retValue);
              return;
            }
            callback();
          });
        },
        //任务提交
        function (callback) {
          DAL_Factory.Business.User_Task({
            User_ID: parm.StateData.User_ID,
            User_NickName: parm.StateData.NickName,
            User_RealName: parm.StateData.RealName,
            Task_ID: 1000,
            Task_Progress: 1,
            Create_IP: parm.Create_IP
          }, function () {
            callback();
          });
        },
        //记录登录日志
        function (callback) {
          DAL_Factory.Log.User_Login.Insert({
            User_ID: parm.StateData.User_ID,
            NickName: parm.StateData.NickName,
            RealName: parm.StateData.RealName,
            IsAnchor: parm.StateData.IsAnchor,
            IsFamily: parm.StateData.IsFamily,
            IsAdmin: parm.StateData.IsAdmin,
            IsIDCard: parm.StateData.IsIDCard,
            IsChargeFirst: parm.StateData.IsChargeFirst,
            Channel_ID: parm.StateData.Channel_ID,
            Inviter_ID: parm.StateData.Inviter_ID,
            SignUp_Anchor_ID: parm.StateData.SignUp_Anchor_ID,
            SignUp_Anchor_Family_ID: parm.StateData.SignUp_Anchor_Family_ID,
            SignUp_Origin: parm.StateData.SignUp_Origin,
            SignUp_Date: parm.StateData.SignUp_Date,
            SignIn_Origin: parm.SignIn_Origin,
            SignIn_Type: parm.SignIn_Type,
            Create_IP: parm.Create_IP
          }, function () {
            callback();
          });
        }
      ], function (retValue) {
        if (retValue) {
          callback(retValue);
          return;
        }
        callback(KOC.ReturnValue.New({
          returnObject: parm.StateData
        }));
      });
    },
    //endregion
    //region User_LoginQQ:用户注册登录绑定(QQ互联)
    User_LoginQQ: function (parm, callback) {
      parm = KOC.Lodash.extend({
        User_ID: -1,
        OAuth_QQ_ID: null,
        OAuth_QQ_Token: null,
        OAuth_QQ_ExpiresIn: null,
        OAuth_QQ_RefreshToken: null,
        NickName: null,
        Sex: null,
        Channel_ID: null,
        Inviter_ID: null,
        Room_ID: null,
        SignUp_Origin: -1,
        SignUp_Url: "",
        Create_IP: ""
      }, parm);
      KOC.Async.series([
        //QQ绑定
        function (callback) {
          DAL_Factory.Business.User_OAuthQQ({
            User_ID: parm.User_ID,
            OAuth_QQ_ID: parm.OAuth_QQ_ID,
            OAuth_QQ_Token: parm.OAuth_QQ_Token,
            OAuth_QQ_ExpiresIn: parm.OAuth_QQ_ExpiresIn,
            OAuth_QQ_RefreshToken: parm.OAuth_QQ_RefreshToken,
            NickName: parm.NickName,
            Sex: parm.Sex,
            Channel_ID: parm.Channel_ID,
            Inviter_ID: parm.Inviter_ID,
            Room_ID: parm.Room_ID,
            SignUp_Origin: parm.SignUp_Origin,
            SignUp_Url: parm.SignUp_Url,
            Create_IP: parm.Create_IP
          }, function (retValue) {
            if (retValue.hasError) {
              callback(retValue);
              return;
            }
            parm.User_ID = retValue.returnObject.User_ID;
            callback();
          });
        },
        //用户登录
        function (callback) {
          DAL_Factory.Business.User_Login({
            User_ID: parm.User_ID,
            SignIn_Origin: 0,
            SignIn_Type: 10,
            Create_IP: parm.Create_IP
          }, function (retValue) {
            if (retValue.hasError) {
              callback(retValue);
              return;
            }
            parm.StateData = retValue.returnObject;
            callback();
          });
        }
      ], function (retValue) {
        if (retValue) {
          callback(retValue);
          return;
        }
        callback(KOC.ReturnValue.New({
          returnObject: parm.StateData
        }));
      });
    },
    //endregion
    //region User_LoginWeibo:用户注册登录绑定(微博)
    User_LoginWeibo: function (parm, callback) {
      parm = KOC.Lodash.extend({
        User_ID: -1,
        OAuth_Weibo_ID: null,
        OAuth_Weibo_Token: null,
        OAuth_Weibo_ExpiresIn: null,
        NickName: null,
        Sex: null,
        Channel_ID: null,
        Inviter_ID: null,
        Room_ID: null,
        SignUp_Origin: -1,
        SignUp_Url: "",
        Create_IP: ""
      }, parm);
      KOC.Async.series([
        //Weibo绑定
        function (callback) {
          DAL_Factory.Business.User_OAuthWeibo({
            User_ID: parm.User_ID,
            OAuth_Weibo_ID: parm.OAuth_Weibo_ID,
            OAuth_Weibo_Token: parm.OAuth_Weibo_Token,
            OAuth_Weibo_ExpiresIn: parm.OAuth_Weibo_ExpiresIn,
            NickName: parm.NickName,
            Sex: parm.Sex,
            Channel_ID: parm.Channel_ID,
            Inviter_ID: parm.Inviter_ID,
            Room_ID: parm.Room_ID,
            SignUp_Origin: parm.SignUp_Origin,
            SignUp_Url: parm.SignUp_Url,
            Create_IP: parm.Create_IP
          }, function (retValue) {
            if (retValue.hasError) {
              callback(retValue);
              return;
            }
            parm.User_ID = retValue.returnObject.User_ID;
            callback();
          });
        },
        //用户登录
        function (callback) {
          DAL_Factory.Business.User_Login({
            User_ID: parm.User_ID,
            SignIn_Origin: 0,
            SignIn_Type: 12,
            Create_IP: parm.Create_IP
          }, function (retValue) {
            if (retValue.hasError) {
              callback(retValue);
              return;
            }
            parm.StateData = retValue.returnObject;
            callback();
          });
        }
      ], function (retValue) {
        if (retValue) {
          callback(retValue);
          return;
        }
        callback(KOC.ReturnValue.New({
          returnObject: parm.StateData
        }));
      });
    },
    //endregion
    //region User_LoginWeixin:用户注册登录绑定(Weixin)
    User_LoginWeixin: function (parm, callback) {
      parm = KOC.Lodash.extend({
        User_ID: -1,
        OAuth_Weixin_ID: null,
        OAuth_Weixin_UNIONID: null,
        OAuth_Weixin_Token: null,
        OAuth_Weixin_ExpiresIn: null,
        OAuth_Weixin_RefreshToken: null,
        NickName: null,
        Sex: null,
        Channel_ID: null,
        Inviter_ID: null,
        Room_ID: null,
        SignUp_Origin: -1,
        SignUp_Url: "",
        Create_IP: ""
      }, parm);
      KOC.Async.series([
        //Weixin绑定
        function (callback) {
          DAL_Factory.Business.User_OAuthWeixin({
            User_ID: parm.User_ID,
            OAuth_Weixin_ID: parm.OAuth_Weixin_ID,
            OAuth_Weixin_UNIONID: parm.OAuth_Weixin_UNIONID,
            OAuth_Weixin_Token: parm.OAuth_Weixin_Token,
            OAuth_Weixin_ExpiresIn: parm.OAuth_Weixin_ExpiresIn,
            OAuth_Weixin_RefreshToken: parm.OAuth_Weixin_RefreshToken,
            NickName: parm.NickName,
            Sex: parm.Sex,
            Channel_ID: parm.Channel_ID,
            Inviter_ID: parm.Inviter_ID,
            Room_ID: parm.Room_ID,
            SignUp_Origin: parm.SignUp_Origin,
            SignUp_Url: parm.SignUp_Url,
            Create_IP: parm.Create_IP
          }, function (retValue) {
            if (retValue.hasError) {
              callback(retValue);
              return;
            }
            parm.User_ID = retValue.returnObject.User_ID;
            callback();
          });
        },
        //用户登录
        function (callback) {
          DAL_Factory.Business.User_Login({
            User_ID: parm.User_ID,
            SignIn_Origin: 0,
            SignIn_Type: 11,
            Create_IP: parm.Create_IP
          }, function (retValue) {
            if (retValue.hasError) {
              callback(retValue);
              return;
            }
            parm.StateData = retValue.returnObject;
            callback();
          });
        }
      ], function (retValue) {
        if (retValue) {
          callback(retValue);
          return;
        }
        callback(KOC.ReturnValue.New({
          returnObject: parm.StateData
        }));
      });
    },
    //endregion
    //region User_MobileResponse:移动端响应
    User_MobileResponse: function (parm, callback) {
      parm = KOC.Lodash.extend({
        Equipment_Code: "",
        Equipment_Type: -1,
        APP_Type: -1,
        Create_IP: ""
      }, parm);
      parm.Mobile_ID = -1;
      parm.Equipment_Type = KOC.StringUtils.ToIntPositive(parm.Equipment_Type);
      parm.APP_Type = KOC.StringUtils.ToIntPositive(parm.APP_Type);
      //验证Equipment_Type&APP_Type
      var retValue = KOC.ReturnValue.New();
      retValue.hasError = true;
      switch (parm.Equipment_Type) {
        case 1: //android
          switch (parm.APP_Type) {
            case 100://个人用户版
              retValue.hasError = false;
              break;
          }
          break;
        case 2: //android pad
          break;
        case 3: //iphone
          switch (parm.APP_Type) {
            case 300:   //个人用户版
              retValue.hasError = false;
              break;
          }
          break;
        case 4: //ipad
          break;
      }
      if (retValue.hasError) {
        retValue.message = "未支持的APP";
        callback(retValue);
        return;
      }
      KOC.Async.series([
        //读取用户移动设备信息
        function (callback) {
          DAL_Factory.User.User_Mobile.Info_EquipmentCode(parm.Equipment_Code, function (retValue) {
            if (retValue.hasError) {
              callback(retValue);
              return;
            }
            if (retValue.returnObject) {
              parm.Mobile_ID = retValue.returnObject.Mobile_ID;
            }
            callback();
          });
        },
        //添加新设备
        function (callback) {
          if (parm.Mobile_ID > 0) {
            callback();
            return;
          }
          DAL_Factory.User.User_Mobile.Insert({
            Equipment_Type: parm.Equipment_Type,
            Equipment_Code: parm.Equipment_Code,
            Create_IP: parm.Create_IP
          }, function (retValue) {
            if (retValue.hasError) {
              callback(retValue);
              return;
            }
            parm.Mobile_ID = retValue.GetValue("insertId");
            callback();
          });
        },
        //添加新应用
        function (callback) {
          DAL_Factory.User.User_Mobile_APP.Info(parm.Mobile_ID, parm.APP_Type, function (retValue) {
            if (retValue.hasError) {
              callback(retValue);
              return;
            }
            if (retValue.returnObject) {
              callback();
              return;
            }
            DAL_Factory.User.User_Mobile_APP.Insert({
              Mobile_ID: parm.Mobile_ID,
              APP_Type: parm.APP_Type,
              Create_IP: parm.Create_IP
            }, function (retValue) {
              if (retValue.hasError) {
                callback(retValue);
                return;
              }
              callback();
            });
          })
        },
        //生成APP授权码
        function (callback) {
          DAL_Factory.User.User_Mobile_APP.Update_AuthCode({
            Mobile_ID: parm.Mobile_ID,
            APP_Type: parm.APP_Type
          }, function (retValue) {
            if (retValue.hasError) {
              callback(retValue);
              return;
            }
            parm.Auth_Code = retValue.returnObject;
            callback();
          });
        }
      ], function (retValue) {
        if (retValue) {
          callback(retValue);
          return;
        }
        callback(KOC.ReturnValue.New({
          returnObject: {
            Mobile_ID: parm.Mobile_ID,
            Auth_Code: parm.Auth_Code,
            Equipment_Type: parm.Equipment_Type,
            APP_Type: parm.APP_Type
          }
        }));
      });
    },
    //endregion
    //region User_MobileAuthVerify:移动端验证
    User_MobileAuthVerify: function (parm, callback) {
      parm = KOC.Lodash.extend({
        Mobile_ID: -1,
        APP_Type: -1,
        Sign: ""
      }, parm);
      KOC.Async.series([
        //读取设备信息
        function (callback) {
          DAL_Factory.User.User_Mobile.Info(parm.Mobile_ID, function (retValue) {
            if (retValue.hasError) {
              callback(retValue);
              return;
            }
            if (!retValue.returnObject) {
              retValue.hasError = true;
              retValue.message = "未找到相关设备信息";
              callback(retValue);
              return;
            }
            parm.Equipment_Code = retValue.returnObject.Equipment_Code;
            parm.User_ID = retValue.returnObject.User_ID;
            callback();
          });
        },
        //读取设备APP信息
        function (callback) {
          DAL_Factory.User.User_Mobile_APP.Info(parm.Mobile_ID, parm.APP_Type, function (retValue) {
            if (retValue.hasError) {
              callback(retValue);
              return;
            }
            if (!retValue.returnObject) {
              retValue.hasError = true;
              retValue.message = "未找到相关设备APP信息";
              callback(retValue);
              return;
            }
            parm.Auth_Code = retValue.returnObject.Auth_Code;
            parm.APP_Version = retValue.returnObject.APP_Version ? String(retValue.returnObject.APP_Version) : null;
            callback();
          });
        }
      ], function (retValue) {
        if (retValue) {
          callback(retValue);
          return;
        }
        //验证签名串
        if (KOC.StringUtils.MD5(parm.Equipment_Code + "|" + parm.Auth_Code) != String(parm.Sign).toLowerCase()) {
          callback(KOC.ReturnValue.New({
            hasError: true,
            errorCode: -1,
            message: "签名串错误"
          }));
          return;
        }
        callback(KOC.ReturnValue.New({
          returnObject: {
            User_ID: parm.User_ID,
            APP_Version: parm.APP_Version
          }
        }));
      });
    },
    //endregion
    //region User_MobileOpen:移动端打开
    User_MobileOpen: function (parm, callback) {
      parm = KOC.Lodash.extend({
        Mobile_ID: -1,
        APP_Type: -1,
        Sign: "",
        Equipment_Name: "",
        Screen_Width: -1,
        Screen_Height: -1,
        OS_Version: "",
        APP_Version: "",
        APP_VersionCode: -1,
        Longitude: -1,
        Latitude: -1,
        Create_IP: ""
      }, parm);
      KOC.Async.series([
        //验证加密串
        function (callback) {
          DAL_Factory.Business.User_MobileAuthVerify({
            Mobile_ID: parm.Mobile_ID,
            APP_Type: parm.APP_Type,
            Sign: parm.Sign
          }, function (retValue) {
            if (retValue.hasError) {
              callback(retValue);
              return;
            }
            parm.User_ID = retValue.returnObject.User_ID;
            callback();
          });
        },
        //修改用户移动设备信息
        function (callback) {
          DAL_Factory.User.User_Mobile.Update_Open({
            Equipment_Name: parm.Equipment_Name,
            Screen_Width: parm.Screen_Width,
            Screen_Height: parm.Screen_Height,
            OS_Version: parm.OS_Version,
            Longitude: parm.Longitude,
            Latitude: parm.Latitude,
            Mobile_ID: parm.Mobile_ID
          }, function (retValue) {
            if (retValue.hasError) {
              callback(retValue);
              return;
            }
            if (retValue.returnObject !== 1) {
              retValue.hasError = true;
              retValue.message = "修改用户移动设备信息出错(影响" + retValue.returnObject + "行)";
              callback(retValue);
              return;
            }
            callback();
          });
        },
        //修改用户移动设备APP信息
        function (callback) {
          DAL_Factory.User.User_Mobile_APP.Update_Open({
            APP_Version: parm.APP_Version,
            APP_VersionCode: parm.APP_VersionCode,
            Mobile_ID: parm.Mobile_ID,
            APP_Type: parm.APP_Type
          }, function (retValue) {
            if (retValue.hasError) {
              callback(retValue);
              return;
            }
            if (retValue.returnObject !== 1) {
              retValue.hasError = true;
              retValue.message = "修改用户移动设备APP信息出错(影响" + retValue.returnObject + "行)";
              callback(retValue);
              return;
            }
            callback();
          });
        },
        //最后登录信息User
        function (callback) {
          if (!parm.User_ID || parm.User_ID <= 0) {
            callback();
            return;
          }
          DAL_Factory.User.User_Info.Update_Login({
            Login_This_IP: parm.Create_IP,
            User_ID: parm.User_ID
          }, function () {
            callback();
          });
        },
        //取得用户状态
        function (callback) {
          if (!parm.User_ID || parm.User_ID <= 0) {
            parm.StateData = StateModel.New();
            callback();
            return;
          }
          DAL_Factory.Business.User_StateData(parm.User_ID, function (retValue) {
            if (retValue.hasError) {
              parm.User_ID = -1;
              parm.StateData = StateModel.New();
            }
            parm.StateData = retValue.returnObject;
            callback();
          });
        },
        //写入登录日志
        function (callback) {
          if (!parm.User_ID || parm.User_ID <= 0) {
            callback();
            return;
          }
          DAL_Factory.Log.User_Login.Insert({
            User_ID: parm.StateData.User_ID,
            NickName: parm.StateData.NickName,
            RealName: parm.StateData.RealName,
            IsAnchor: parm.StateData.IsAnchor,
            IsFamily: parm.StateData.IsFamily,
            IsAdmin: parm.StateData.IsAdmin,
            IsIDCard: parm.StateData.IsIDCard,
            IsChargeFirst: parm.StateData.IsChargeFirst,
            Channel_ID: parm.StateData.Channel_ID,
            Inviter_ID: parm.StateData.Inviter_ID,
            SignUp_Anchor_ID: parm.StateData.SignUp_Anchor_ID,
            SignUp_Anchor_Family_ID: parm.StateData.SignUp_Anchor_Family_ID,
            SignUp_Origin: parm.StateData.SignUp_Origin,
            SignUp_Date: parm.StateData.SignUp_Date,
            SignIn_Origin: parm.APP_Type,
            SignIn_Type: 1,
            Create_IP: parm.Create_IP
          }, function () {
            callback();
          });
        }
      ], function (retValue) {
        if (retValue) {
          callback(retValue);
          return;
        }
        callback(KOC.ReturnValue.New({
          returnObject: parm.StateData
        }));
      });
    },
    //endregion
    //region User_MobileLogin:移动端用户登录
    User_MobileLogin: function (parm, callback) {
      parm = KOC.Lodash.extend({
        Mobile_ID: -1,
        APP_Type: -1,
        Sign: "",
        User_ID: null,
        LoginName: "",
        Password: "",
        SignIn_Type: -1, //登录方式 -1:未知 1:记住 2:用户名 10:QQ 11:微信 12:微博
        Create_IP: ""
      }, parm);
      KOC.Async.series([
        //验证加密串
        function (callback) {
          if (parm.User_ID && parm.User_ID > 0) {
            callback();
            return;
          }
          DAL_Factory.Business.User_MobileAuthVerify({
            Mobile_ID: parm.Mobile_ID,
            APP_Type: parm.APP_Type,
            Sign: parm.Sign
          }, function (retValue) {
            if (retValue.hasError) {
              callback(retValue);
              return;
            }
            parm.User_ID = retValue.returnObject.User_ID;
            callback();
          });
        },
        //读取用户信息
        function (callback) {
          if (!parm.User_ID || parm.User_ID <= 0) {
            callback();
            return;
          }
          DAL_Factory.User.User_Info.Info(parm.User_ID, function (retValue) {
            if (retValue.hasError) {
              callback(retValue);
              return;
            }
            if (!retValue.returnObject) {
              retValue.hasError = true;
              retValue.message = "用户错误,请核实";
              callback(retValue);
              return;
            }
            if (retValue.returnObject.Status !== 0) {
              retValue.hasError = true;
              retValue.message = "此用户已被锁定,请与管理员联系";
              callback(retValue);
              return;
            }
            parm.User_ID = retValue.returnObject.User_ID;
            parm.NickName = retValue.returnObject.NickName;
            parm.RealName = retValue.returnObject.RealName;
            parm.IsAnchor = retValue.returnObject.IsAnchor;
            parm.IsFamily = retValue.returnObject.IsFamily;
            parm.IsAdmin = retValue.returnObject.IsAdmin;
            parm.IsIDCard = retValue.returnObject.IDCard_Status == 0;
            parm.IsChargeFirst = !!retValue.returnObject.Charge_First;
            parm.Inviter_ID = retValue.returnObject.Inviter_ID;
            parm.SignUp_Anchor_ID = retValue.returnObject.SignUp_Anchor_ID;
            parm.SignUp_Anchor_Family_ID = retValue.returnObject.SignUp_Anchor_Family_ID;
            parm.SignUp_Origin = retValue.returnObject.SignUp_Origin;
            parm.SignUp_Date = retValue.returnObject.Create_Date;
            callback();
          });
        },
        //读取用户信息
        function (callback) {
          if (parm.User_ID && parm.User_ID > 0) {
            callback();
            return;
          }
          DAL_Factory.User.User_Info.Info_Login(parm.LoginName, function (retValue) {
            if (retValue.hasError) {
              callback(retValue);
              return;
            }
            if (!retValue.returnObject) {
              retValue.hasError = true;
              retValue.message = "用户名错误,请核实";
              callback(retValue);
              return;
            }
            if (retValue.returnObject.Status !== 0) {
              retValue.hasError = true;
              retValue.message = "此用户已被锁定,请与管理员联系";
              callback(retValue);
              return;
            }
            if (KOC.StringUtils.MD5(parm.Password + retValue.returnObject.PasswordKey) != retValue.returnObject.Password) {
              retValue.hasError = true;
              retValue.message = "密码不正确";
              callback(retValue);
              return;
            }
            if (parm.User_ID == retValue.returnObject.User_ID) {
              retValue.hasError = true;
              retValue.message = "您已经登录了此帐号";
              callback(retValue);
              return;
            }
            parm.User_ID = retValue.returnObject.User_ID;
            parm.NickName = retValue.returnObject.NickName;
            parm.RealName = retValue.returnObject.RealName;
            parm.IsAnchor = retValue.returnObject.IsAnchor;
            parm.IsFamily = retValue.returnObject.IsFamily;
            parm.IsAdmin = retValue.returnObject.IsAdmin;
            parm.IsIDCard = retValue.returnObject.IDCard_Status == 0;
            parm.IsChargeFirst = !!retValue.returnObject.Charge_First;
            parm.Channel_ID = retValue.returnObject.Channel_ID;
            parm.Inviter_ID = retValue.returnObject.Inviter_ID;
            parm.SignUp_Anchor_ID = retValue.returnObject.SignUp_Anchor_ID;
            parm.SignUp_Anchor_Family_ID = retValue.returnObject.SignUp_Anchor_Family_ID;
            parm.SignUp_Origin = retValue.returnObject.SignUp_Origin;
            parm.SignUp_Date = retValue.returnObject.Create_Date;
            callback();
          });
        },
        //修改用户移动设备归属
        function (callback) {
          DAL_Factory.User.User_Mobile.Update_UserID({
            User_ID: parm.User_ID,
            Mobile_ID: parm.Mobile_ID
          }, function (retValue) {
            if (retValue.hasError) {
              callback(retValue);
              return;
            }
            if (retValue.returnObject !== 1) {
              retValue.hasError = true;
              retValue.message = "修改用户移动设备归属出错，影响行(" + retValue.returnObject + ")";
              callback(retValue);
              return;
            }
            callback();
          });
        },
        //任务提交
        function (callback) {
          DAL_Factory.Business.User_Task({
            User_ID: parm.User_ID,
            Task_ID: 1000,
            Task_Progress: 1,
            Create_IP: parm.Create_IP
          }, function () {
            callback();
          });
        },
        //记录登录日志
        function (callback) {
          DAL_Factory.Log.User_Login.Insert({
            User_ID: parm.User_ID,
            NickName: parm.NickName,
            RealName: parm.RealName,
            IsAnchor: parm.IsAnchor,
            IsFamily: parm.IsFamily,
            IsAdmin: parm.IsAdmin,
            IsIDCard: parm.IsIDCard,
            IsChargeFirst: parm.IsChargeFirst,
            Channel_ID: parm.Channel_ID,
            Inviter_ID: parm.Inviter_ID,
            SignUp_Anchor_ID: parm.SignUp_Anchor_ID,
            SignUp_Anchor_Family_ID: parm.SignUp_Anchor_Family_ID,
            SignUp_Origin: parm.SignUp_Origin,
            SignUp_Date: parm.SignUp_Date,
            SignIn_Origin: parm.APP_Type,
            SignIn_Type: parm.SignIn_Type,
            Create_IP: parm.Create_IP
          }, function () {
            callback();
          });
        }
      ], function (retValue) {
        if (retValue) {
          callback(retValue);
          return;
        }
        callback(KOC.ReturnValue.New());
      });
    },
    //endregion
    //region User_MobileLoginQQ:移动端用户登录绑定(QQ互联)
    User_MobileLoginQQ: function (parm, callback) {
      parm = KOC.Lodash.extend({
        Mobile_ID: -1,
        APP_Type: -1,
        Sign: "",
        OAuth_QQ_ID: null,
        OAuth_QQ_Token: null,
        OAuth_QQ_ExpiresIn: null,
        OAuth_QQ_RefreshToken: null,
        NickName: null,
        Sex: null,
        Channel_ID: "",
        Create_IP: ""
      }, parm);
      KOC.Async.series([
        //验证加密串
        function (callback) {
          DAL_Factory.Business.User_MobileAuthVerify({
            Mobile_ID: parm.Mobile_ID,
            APP_Type: parm.APP_Type,
            Sign: parm.Sign
          }, function (retValue) {
            if (retValue.hasError) {
              callback(retValue);
              return;
            }
            parm.User_ID = retValue.returnObject.User_ID;
            parm.APP_Version = retValue.returnObject.APP_Version;
            parm.SignUp_Url = "APP:" + (parm.APP_Type == 100 ? "Android" : "IOS") + ",APP_Type:" + parm.APP_Type + ",APP_Version:" + parm.APP_Version;
            callback();
          });
        },
        //QQ绑定
        function (callback) {
          DAL_Factory.Business.User_OAuthQQ({
            User_ID: parm.User_ID,
            OAuth_QQ_ID: parm.OAuth_QQ_ID,
            OAuth_QQ_Token: parm.OAuth_QQ_Token,
            OAuth_QQ_ExpiresIn: parm.OAuth_QQ_ExpiresIn,
            OAuth_QQ_RefreshToken: parm.OAuth_QQ_RefreshToken,
            NickName: parm.NickName,
            Sex: parm.Sex,
            Channel_ID: parm.Channel_ID,
            SignUp_Origin: parm.APP_Type,
            SignUp_Url: parm.SignUp_Url,
            Create_IP: parm.Create_IP
          }, function (retValue) {
            if (retValue.hasError) {
              callback(retValue);
              return;
            }
            parm.User_ID = retValue.returnObject.User_ID;
            callback();
          });
        },
        //移动端用户登录
        function (callback) {
          DAL_Factory.Business.User_MobileLogin({
            Mobile_ID: parm.Mobile_ID,
            User_ID: parm.User_ID,
            SignIn_Type: 10,
            Create_IP: parm.Create_IP
          }, function (retValue) {
            if (retValue.hasError) {
              callback(retValue);
              return;
            }
            callback();
          });
        }
      ], function (retValue) {
        if (retValue) {
          callback(retValue);
          return;
        }
        callback(KOC.ReturnValue.New());
      });
    },
    //endregion
    //region User_MobileLoginWeibo:移动端用户登录绑定(微博)
    User_MobileLoginWeibo: function (parm, callback) {
      parm = KOC.Lodash.extend({
        Mobile_ID: -1,
        APP_Type: -1,
        Sign: "",
        OAuth_Weibo_ID: null,
        OAuth_Weibo_Token: null,
        OAuth_Weibo_ExpiresIn: null,
        NickName: null,
        Sex: null,
        Channel_ID: "",
        Create_IP: ""
      }, parm);
      KOC.Async.series([
        //验证加密串
        function (callback) {
          DAL_Factory.Business.User_MobileAuthVerify({
            Mobile_ID: parm.Mobile_ID,
            APP_Type: parm.APP_Type,
            Sign: parm.Sign
          }, function (retValue) {
            if (retValue.hasError) {
              callback(retValue);
              return;
            }
            parm.User_ID = retValue.returnObject.User_ID;
            parm.APP_Version = retValue.returnObject.APP_Version;
            parm.SignUp_Url = "APP:" + (parm.APP_Type == 100 ? "Android" : "IOS") + ",APP_Type:" + parm.APP_Type + ",APP_Version:" + parm.APP_Version;
            callback();
          });
        },
        //Weibo绑定
        function (callback) {
          DAL_Factory.Business.User_OAuthWeibo({
            User_ID: parm.User_ID,
            OAuth_Weibo_ID: parm.OAuth_Weibo_ID,
            OAuth_Weibo_Token: parm.OAuth_Weibo_Token,
            OAuth_Weibo_ExpiresIn: parm.OAuth_Weibo_ExpiresIn,
            NickName: parm.NickName,
            Sex: parm.Sex,
            Channel_ID: parm.Channel_ID,
            SignUp_Origin: parm.APP_Type,
            SignUp_Url: parm.SignUp_Url,
            Create_IP: parm.Create_IP
          }, function (retValue) {
            if (retValue.hasError) {
              callback(retValue);
              return;
            }
            parm.User_ID = retValue.returnObject.User_ID;
            callback();
          });
        },
        //移动端用户登录
        function (callback) {
          DAL_Factory.Business.User_MobileLogin({
            Mobile_ID: parm.Mobile_ID,
            User_ID: parm.User_ID,
            SignIn_Type: 12,
            Create_IP: parm.Create_IP
          }, function (retValue) {
            if (retValue.hasError) {
              callback(retValue);
              return;
            }
            callback();
          });
        }
      ], function (retValue) {
        if (retValue) {
          callback(retValue);
          return;
        }
        callback(KOC.ReturnValue.New());
      });
    },
    //endregion
    //region User_MobileLoginWeixin:移动端用户登录绑定(Weixin)
    User_MobileLoginWeixin: function (parm, callback) {
      parm = KOC.Lodash.extend({
        Mobile_ID: -1,
        APP_Type: -1,
        Sign: "",
        OAuth_Weixin_ID: null,
        OAuth_Weixin_UNIONID: null,
        OAuth_Weixin_Token: null,
        OAuth_Weixin_ExpiresIn: null,
        OAuth_Weixin_RefreshToken: null,
        NickName: null,
        Sex: null,
        Channel_ID: "",
        Create_IP: ""
      }, parm);
      KOC.Async.series([
        //验证加密串
        function (callback) {
          DAL_Factory.Business.User_MobileAuthVerify({
            Mobile_ID: parm.Mobile_ID,
            APP_Type: parm.APP_Type,
            Sign: parm.Sign
          }, function (retValue) {
            if (retValue.hasError) {
              callback(retValue);
              return;
            }
            parm.User_ID = retValue.returnObject.User_ID;
            parm.APP_Version = retValue.returnObject.APP_Version;
            parm.SignUp_Url = "APP:" + (parm.APP_Type == 100 ? "Android" : "IOS") + ",APP_Type:" + parm.APP_Type + ",APP_Version:" + parm.APP_Version;
            callback();
          });
        },
        //Weixin绑定
        function (callback) {
          DAL_Factory.Business.User_OAuthWeixin({
            User_ID: parm.User_ID,
            OAuth_Weixin_ID: parm.OAuth_Weixin_ID,
            OAuth_Weixin_UNIONID: parm.OAuth_Weixin_UNIONID,
            OAuth_Weixin_Token: parm.OAuth_Weixin_Token,
            OAuth_Weixin_ExpiresIn: parm.OAuth_Weixin_ExpiresIn,
            OAuth_Weixin_RefreshToken: parm.OAuth_Weixin_RefreshToken,
            NickName: parm.NickName,
            Sex: parm.Sex,
            Channel_ID: parm.Channel_ID,
            SignUp_Origin: parm.APP_Type,
            SignUp_Url: parm.SignUp_Url,
            Create_IP: parm.Create_IP
          }, function (retValue) {
            if (retValue.hasError) {
              callback(retValue);
              return;
            }
            parm.User_ID = retValue.returnObject.User_ID;
            callback();
          });
        },
        //移动端用户登录
        function (callback) {
          DAL_Factory.Business.User_MobileLogin({
            Mobile_ID: parm.Mobile_ID,
            User_ID: parm.User_ID,
            SignIn_Type: 11,
            Create_IP: parm.Create_IP
          }, function (retValue) {
            if (retValue.hasError) {
              callback(retValue);
              return;
            }
            callback();
          });
        }
      ], function (retValue) {
        if (retValue) {
          callback(retValue);
          return;
        }
        callback(KOC.ReturnValue.New());
      });
    },
    //endregion
    //region User_MobileLoginPhone:移动端用户登录绑定(Phone)
    User_MobileLoginPhone: function (parm, callback) {
      parm = KOC.Lodash.extend({
        Mobile_ID: -1,
        APP_Type: -1,
        Sign: "",
        OAuth_Phone: null,
        PhoneCode: null,
        Password: null,
        Type: null,
        Channel_ID: "",
        Create_IP: ""
      }, parm);
      KOC.Async.series([
        //验证加密串
        function (callback) {
          DAL_Factory.Business.User_MobileAuthVerify({
            Mobile_ID: parm.Mobile_ID,
            APP_Type: parm.APP_Type,
            Sign: parm.Sign
          }, function (retValue) {
            if (retValue.hasError) {
              callback(retValue);
              return;
            }
            parm.User_ID = retValue.returnObject.User_ID;
            parm.APP_Version = retValue.returnObject.APP_Version;
            parm.SignUp_Url = "APP:" + (parm.APP_Type == 100 ? "Android" : "IOS") + ",APP_Type:" + parm.APP_Type + ",APP_Version:" + parm.APP_Version;
            callback();
          });
        },
        //手机号绑定
        function (callback) {
          DAL_Factory.Business.User_OAuthPhone({
            User_ID: parm.User_ID,
            OAuth_Phone: parm.OAuth_Phone,
            PhoneCode: parm.PhoneCode,
            Password: parm.Password,
            Type: parm.Type,
            Channel_ID: parm.Channel_ID,
            SignUp_Origin: parm.APP_Type,
            SignUp_Url: parm.SignUp_Url,
            Create_IP: parm.Create_IP
          }, function (retValue) {
            if (retValue.hasError) {
              callback(retValue);
              return;
            }
            parm.User_ID = retValue.returnObject.User_ID;
            callback();
          });
        },
        //移动端用户登录
        function (callback) {
          DAL_Factory.Business.User_MobileLogin({
            Mobile_ID: parm.Mobile_ID,
            User_ID: parm.User_ID,
            SignIn_Type: 2,
            Create_IP: parm.Create_IP
          }, function (retValue) {
            if (retValue.hasError) {
              callback(retValue);
              return;
            }
            callback();
          });
        }
      ], function (retValue) {
        if (retValue) {
          callback(retValue);
          return;
        }
        callback(KOC.ReturnValue.New());
      });
    },
    //endregion
    //region User_MobileLogout:移动端用户退出
    User_MobileLogout: function (parm, callback) {
      parm = KOC.Lodash.extend({
        Mobile_ID: -1,
        APP_Type: -1,
        Sign: ""
      }, parm);
      KOC.Async.series([
        //验证加密串
        function (callback) {
          DAL_Factory.Business.User_MobileAuthVerify({
            Mobile_ID: parm.Mobile_ID,
            APP_Type: parm.APP_Type,
            Sign: parm.Sign
          }, function (retValue) {
            if (retValue.hasError) {
              callback(retValue);
              return;
            }
            if (!retValue.returnObject.User_ID || retValue.returnObject.User_ID <= 0) {
              retValue.hasError = true;
              retValue.message = "您现在还没有登录";
              callback(retValue);
              return;
            }
            callback();
          });
        },
        //修改用户移动设备归属
        function (callback) {
          DAL_Factory.User.User_Mobile.Update_UserID({
            Mobile_ID: parm.Mobile_ID
          }, function (retValue) {
            if (retValue.hasError) {
              callback(retValue);
              return;
            }
            if (retValue.returnObject !== 1) {
              retValue.hasError = true;
              retValue.message = "修改用户移动设备归属出错，影响行(" + retValue.returnObject + ")";
              callback(retValue);
              return;
            }
            callback();
          });
        }
      ], function (retValue) {
        if (retValue) {
          callback(retValue);
          return;
        }
        callback(KOC.ReturnValue.New());
      });
    },
    //endregion
    //region User_PackageTransction:用户包裹交易
    User_PackageTransction: function (Conn, parm, callback) {
      if (!Conn) {
        callback(KOC.ReturnValue.New({
          hasError: false,
          message: "Connection is null"
        }));
        return;
      }
      parm = KOC.Lodash.extend({
        User_ID: -1,
        Item_Type: null, //Gift Horn
        Item_ID: null,
        Trade_Type: null,
        Trade_Flag: 0,
        Trade_Num: 0,
        Trade_Order_No: "",
        Remark: "",
        Create_IP: ""
      }, parm);
      if (parm.Trade_Num <= 0) {
        callback(KOC.ReturnValue.New({
          hasError: false,
          message: "交易数量传入错误"
        }));
        return;
      }
      var _UserPackageTransaction = CommonUtils.User.PackageTransaction.fnInfo(parm.Trade_Type);
      if (!_UserPackageTransaction || _UserPackageTransaction.Flag != parm.Trade_Flag) {
        callback(KOC.ReturnValue.New({
          hasError: false,
          message: "传入参数错误，用户包裹交易记录数据不匹配"
        }));
        return;
      }
      parm.Trade_Type_Name = _UserPackageTransaction.Name;
      KOC.Async.series([
        //读取包裹项目数据
        function (callback) {
          switch (parm.Item_Type) {
            case "Gift":
              parm.Item_Info = CommonUtils.Commodity.Gift.fnInfo(KOC.StringUtils.ToIntPositive(parm.Item_ID));
              break;
            case "Horn":
              parm.Item_Info = CommonUtils.Commodity.Horn.fnInfo(parm.Item_ID);
              break;
          }
          if (!parm.Item_Info) {
            callback(KOC.ReturnValue.New({
              hasError: false,
              message: "传入项目ID错误"
            }));
            return;
          }
          parm.Item_Name = parm.Item_Info.Name;
          callback();
        },
        //初始包裹数据
        function (callback) {
          DAL_Factory.User.User_Package.Insert(Conn, {
            User_ID: parm.User_ID,
            Item_Type: parm.Item_Type,
            Item_ID: parm.Item_ID,
            Item_Name: parm.Item_Name
          }, function () {
            callback();
          });
        },
        //包裹操作
        function (callback) {
          DAL_Factory.User.User_Package.Update(Conn, {
            Trade_Flag: parm.Trade_Flag,
            Trade_Num: parm.Trade_Num,
            User_ID: parm.User_ID,
            Item_Type: parm.Item_Type,
            Item_ID: parm.Item_ID,
            Item_Name: parm.Item_Name
          }, function (retValue) {
            if (retValue.hasError) {
              callback(retValue);
              return;
            }
            if (retValue.returnObject !== 1) {
              retValue.hasError = true;
              retValue.message = "修改用户包裹数据出错，影响行(" + retValue.returnObject + ")";
              retValue.returnObject = parm;
              callback(retValue);
              return;
            }
            callback();
          });
        },
        //交易记录
        function (callback) {
          DAL_Factory.User.User_Package_Trade.Insert(Conn, {
            User_ID: parm.User_ID,
            Item_Type: parm.Item_Type,
            Item_ID: parm.Item_ID,
            Trade_Type: parm.Trade_Type,
            Trade_Type_Name: parm.Trade_Type_Name,
            Trade_Flag: parm.Trade_Flag,
            Trade_Num: parm.Trade_Num,
            Trade_Order_No: parm.Trade_Order_No,
            Remark: parm.Remark,
            Create_IP: parm.Create_IP
          }, function (retValue) {
            if (retValue.hasError) {
              callback(retValue);
              return;
            }
            if (retValue.returnObject !== 1) {
              retValue.hasError = true;
              retValue.message = "写入用户包裹交易记录出错，影响行(" + retValue.returnObject + ")";
              callback(retValue);
              return;
            }
            callback();
          });
        }
      ], function (retValue) {
        if (retValue) {
          callback(retValue);
          return;
        }
        callback(KOC.ReturnValue.New());
      });
    },
    //endregion
    //region User_BankTransction:用户帐户资金交易(币/豆)
    User_BankTransction: function (Conn, parm, callback) {
      if (!Conn) {
        callback(KOC.ReturnValue.New({
          hasError: false,
          message: "Connection is null"
        }));
        return;
      }
      parm = KOC.Lodash.extend({
        User_ID: -1,
        Related_User_ID: -1,
        Related_User_NickName: "",
        Related_User_RealName: "",
        Related_Family_ID: -1,
        Related_Family_Name: "",
        Trade_Currency: -1,
        Trade_Type: -1,
        Trade_Flag: 0,
        Trade_Amt: 0,
        Trade_Order_No: -1,
        Remark: "",
        Create_IP: ""
      }, parm);
      if (parm.Trade_Amt <= 0) {
        callback(KOC.ReturnValue.New({
          hasError: false,
          message: "交易金额传入错误"
        }));
        return;
      }
      var _UserBankTransaction = CommonUtils.User.BankTransaction.fnInfo(parm.Trade_Type);
      if (!_UserBankTransaction || _UserBankTransaction.Flag != parm.Trade_Flag || _UserBankTransaction.Currency != parm.Trade_Currency) {
        callback(KOC.ReturnValue.New({
          hasError: false,
          message: "传入参数错误，交易记录数据不匹配"
        }));
        return;
      }
      parm.Trade_Type_Name = _UserBankTransaction.Name;
      KOC.Async.series([
        //资金操作
        function (callback) {
          DAL_Factory.User.User_Info.Update_Bank(Conn, {
            Trade_Currency: parm.Trade_Currency,
            Trade_Flag: parm.Trade_Flag,
            Trade_Amt: parm.Trade_Amt,
            User_ID: parm.User_ID
          }, function (retValue) {
            if (retValue.hasError) {
              callback(retValue);
              return;
            }
            if (retValue.returnObject !== 1) {
              retValue.hasError = true;
              retValue.message = "修改用户资金数据出错，影响行(" + retValue.returnObject + ")";
              retValue.returnObject = parm;
              callback(retValue);
              return;
            }
            callback();
          });
        },
        //交易记录
        function (callback) {
          DAL_Factory.User.User_Bank_Trade.Insert(Conn, {
            User_ID: parm.User_ID,
            Related_User_ID: parm.Related_User_ID,
            Related_User_NickName: parm.Related_User_NickName,
            Related_User_RealName: parm.Related_User_RealName,
            Related_Family_ID: parm.Related_Family_ID,
            Related_Family_Name: parm.Related_Family_Name,
            Trade_Currency: parm.Trade_Currency,
            Trade_Type: parm.Trade_Type,
            Trade_Type_Name: parm.Trade_Type_Name,
            Trade_Flag: parm.Trade_Flag,
            Trade_Amt: parm.Trade_Amt,
            Trade_Order_No: parm.Trade_Order_No,
            Remark: parm.Remark,
            Create_IP: parm.Create_IP
          }, function (retValue) {
            if (retValue.hasError) {
              callback(retValue);
              return;
            }
            if (retValue.returnObject !== 1) {
              retValue.hasError = true;
              retValue.message = "写入用户资金交易记录出错，影响行(" + retValue.returnObject + ")";
              callback(retValue);
              return;
            }
            callback();
          });
        }
      ], function (retValue) {
        if (retValue) {
          callback(retValue);
          return;
        }
        callback(KOC.ReturnValue.New());
      });
    },
    //endregion
    //region User_FamilyApply:公会申请入驻
    User_FamilyApply: function (parm, callback) {
      parm = KOC.Lodash.extend({
        User_ID: null,
        Create_IP: null
      }, parm);
      var _Conn = null;
      var _Exist = false;//公会信息是否存在
      if (!parm.Create_IP) {
        callback(KOC.ReturnValue.New({
          hasError: true,
          message: "用户IP不存在"
        }));
        return;
      }
      KOC.Async.series([
        //读取用户信息
        function (callback) {
          DAL_Factory.User.User_Info.Info(parm.User_ID, function (retValue) {
            if (retValue.hasError) {
              callback(retValue);
              return;
            }
            if (!retValue.returnObject) {
              retValue.hasError = true;
              retValue.message = "用户信息不存在";
              callback(retValue);
              return;
            }
            if (retValue.returnObject.IsFamily == 1) {
              //用户已经有公会了
              retValue.hasError = true;
              retValue.message = "用户已经有公会了";
              callback(retValue);
              return;
            }
            callback();
          });
        },
        //读取公会信息
        function (callback) {
          DAL_Factory.User.Family_Info.Info_UserID(parm.User_ID, function (retValue) {
            if (retValue.hasError) {
              callback(retValue);
              return;
            }
            if (retValue.returnObject) {
              _Exist = true;
              parm.Family_ID = retValue.returnObject.Family_ID;
            }
            if (retValue.returnObject && retValue.returnObject.Status == 2) {
              retValue.hasError = true;
              retValue.message = "公会正在申请中";
              callback(retValue);
              return;
            }
            callback();
          });
        },
        //读取redis信息，查看状态
        function (callback) {
          //获取Redis 的数据
          DAL_Factory.RedisCommon.UserFamilyApply.Get(parm.User_ID, function (retValue) {
            if (retValue.hasError) {
              callback(retValue);
              return;
            }
            if (!retValue.returnObject) {
              retValue.hasError = true;
              retValue.message = "redis中的公会入驻申请信息不存在";
              callback(retValue);
              return;
            }
            //查看数据是否全
            var _index = 0;//传入参数数量
            for (var i in retValue.returnObject) {
              _index++;
            }
            if (_index < 11) {
              retValue.hasError = true;
              retValue.message = "redis中的公会入驻申请信息不全，请重新填写";
              callback(retValue);
              return;
            }
            retValue.returnObject.User_ID = parm.User_ID;
            retValue.returnObject.Create_IP = parm.Create_IP;
            retValue.returnObject.Family_ID = parm.Family_ID ? parm.Family_ID : null;
            parm = KOC.Lodash.extend({
              Account_RealName: null,
              Account_CardNo: null,
              Account_BankName: null,
              Account_BankFullName: null,
              Account_Province: null,
              Account_City: null,
              IDCard: null,
              ContactName: null,
              Family_Name: null,
              Phone: null,
              QQ: null,
              Email: null,
              User_ID: null,
              Create_IP: null,
              Family_ID: null
            }, retValue.returnObject);
            callback();
          });
        },
        //开启事物
        function (callback) {
          KOC.MysqlHelper.TranOpen(Config.Mysql.DB.User, function (retValue) {
            if (retValue.hasError) {
              callback(retValue);
              return;
            }
            _Conn = retValue.returnObject;
            callback();
          });
        },
        //写入公会表单
        function (callback) {
          if (_Exist) {
            //存在公会信息，需要修改
            callback();
            return;
          }
          DAL_Factory.User.Family_Info.Insert(_Conn, {
            Account_RealName: parm.Account_RealName,
            Account_CardNo: parm.Account_CardNo,
            Account_BankName: parm.Account_BankName,
            Account_BankFullName: parm.Account_BankFullName,
            Account_Province: parm.Account_Province,
            Account_City: parm.Account_City,
            IDCard: parm.IDCard,
            ContactName: parm.ContactName,
            Family_Name: parm.Family_Name,
            Phone: parm.Phone,
            QQ: parm.QQ,
            Email: parm.Email,
            User_ID: parm.User_ID,
            Create_IP: parm.Create_IP
          }, function (retValue) {
            if (retValue.hasError) {
              callback(retValue);
              return;
            }
            callback();
          });
        },
        //更新公会信息
        function (callback) {
          if (!_Exist) {
            //不存在公会信息
            callback();
            return;
          }
          DAL_Factory.User.Family_Info.Update_Apply(_Conn, {
            Family_ID: parm.Family_ID,
            Account_RealName: parm.Account_RealName,
            Account_CardNo: parm.Account_CardNo,
            Account_BankName: parm.Account_BankName,
            Account_BankFullName: parm.Account_BankFullName,
            Account_Province: parm.Account_Province,
            Account_City: parm.Account_City,
            IDCard: parm.IDCard,
            ContactName: parm.ContactName,
            Family_Name: parm.Family_Name,
            Phone: parm.Phone,
            QQ: parm.QQ,
            Email: parm.Email,
            User_ID: parm.User_ID,
            Create_IP: parm.Create_IP
          }, function (retValue) {
            if (retValue.hasError) {
              callback(retValue);
              return;
            }
            callback();
          });
        }
      ], function (retValue) {
        if (retValue) {
          console.log("公会申请入驻失败:", retValue, parm);
          KOC.MysqlHelper.TranRollback(_Conn, function () {
            callback(retValue);
          });
          return;
        }
        KOC.MysqlHelper.TranCommit(_Conn, function (retValue) {
          if (retValue.hasError) {
            callback(retValue);
            return;
          }
          retValue = KOC.ReturnValue.New();
          retValue.returnObject = parm;
          callback(retValue);
        });
      });
    },
    //endregion
    //region User_FamilyApplyEnter:公会申请入驻(新)
    User_FamilyApplyEnter: function (parm, callback) {
      parm = KOC.Lodash.extend({
        User_ID: null,
        Account_RealName: null,
        Account_CardNo: null,
        Account_BankName: null,
        Account_BankFullName: null,
        Account_Province: null,
        Account_City: null,
        IDCard: null,
        ContactName: null,
        Family_Name: null,
        Phone: null,
        QQ: null,
        Email: null,
        Create_IP: null
      }, parm);
      var _Conn = null;
      parm.Exist = false;//公会信息是否存在
      KOC.Async.series([
        //读取用户信息
        function (callback) {
          DAL_Factory.User.User_Info.Info(parm.User_ID, function (retValue) {
            if (retValue.hasError) {
              callback(retValue);
              return;
            }
            if (!retValue.returnObject) {
              retValue.hasError = true;
              retValue.message = "用户信息不存在";
              callback(retValue);
              return;
            }
            if (retValue.returnObject.IsFamily == 1) {
              //用户已经有公会了
              retValue.hasError = true;
              retValue.message = "用户已经有公会了";
              callback(retValue);
              return;
            }
            callback();
          });
        },
        //艺人公会信息判断
        function (callback) {
          DAL_Factory.User.User_Anchor.Info(parm.User_ID, function (retValue) {
            if (retValue.hasError) {
              callback(retValue);
              return;
            }
            if (retValue.returnObject && retValue.returnObject.Family_ID > 0) {
              retValue.hasError = true;
              retValue.message = "艺人用户已经有公会了";
              callback(retValue);
              return;
            }
            callback();
          });
        },
        //读取公会信息
        function (callback) {
          DAL_Factory.User.Family_Info.Info_UserID(parm.User_ID, function (retValue) {
            if (retValue.hasError) {
              callback(retValue);
              return;
            }
            if (retValue.returnObject) {
              parm.Exist = true;
              parm.Family_ID = retValue.returnObject.Family_ID;
            }
            if (retValue.returnObject && retValue.returnObject.Status == 2) {
              retValue.hasError = true;
              retValue.message = "公会正在申请中";
              callback(retValue);
              return;
            }
            callback();
          });
        },
        //开启事物
        function (callback) {
          KOC.MysqlHelper.TranOpen(Config.Mysql.DB.User, function (retValue) {
            if (retValue.hasError) {
              callback(retValue);
              return;
            }
            _Conn = retValue.returnObject;
            callback();
          });
        },
        //写入公会表单
        function (callback) {
          if (parm.Exist) {
            //存在公会信息，需要修改
            callback();
            return;
          }
          DAL_Factory.User.Family_Info.Insert(_Conn, {
            User_ID: parm.User_ID,
            Account_RealName: parm.Account_RealName,
            Account_CardNo: parm.Account_CardNo,
            Account_BankName: parm.Account_BankName,
            Account_BankFullName: parm.Account_BankFullName,
            Account_Province: parm.Account_Province,
            Account_City: parm.Account_City,
            ContactName: parm.ContactName,
            Family_Name: parm.Family_Name,
            Phone: parm.Phone,
            QQ: parm.QQ,
            Email: parm.Email,
            Create_IP: parm.Create_IP
          }, function (retValue) {
            if (retValue.hasError) {
              callback(retValue);
              return;
            }
            callback();
          });
        },
        //更新公会信息
        function (callback) {
          if (!parm.Exist) {
            //不存在公会信息
            callback();
            return;
          }
          DAL_Factory.User.Family_Info.Update_Apply(_Conn, {
            Family_ID: parm.Family_ID,
            Account_RealName: parm.Account_RealName,
            Account_CardNo: parm.Account_CardNo,
            Account_BankName: parm.Account_BankName,
            Account_BankFullName: parm.Account_BankFullName,
            Account_Province: parm.Account_Province,
            Account_City: parm.Account_City,
            ContactName: parm.ContactName,
            Family_Name: parm.Family_Name,
            Phone: parm.Phone,
            QQ: parm.QQ,
            Email: parm.Email,
            User_ID: parm.User_ID,
            Create_IP: parm.Create_IP
          }, function (retValue) {
            if (retValue.hasError) {
              callback(retValue);
              return;
            }
            callback();
          });
        }
      ], function (retValue) {
        if (retValue) {
          console.log("公会申请入驻失败:", retValue, parm);
          KOC.MysqlHelper.TranRollback(_Conn, function () {
            callback(retValue);
          });
          return;
        }
        KOC.MysqlHelper.TranCommit(_Conn, function (retValue) {
          if (retValue.hasError) {
            callback(retValue);
            return;
          }
          retValue = KOC.ReturnValue.New({
            returnObject: parm
          });
          callback(retValue);
        });
      });
    },
    //endregion
    //region User_FamilyApplyCheck:审批公会申请入驻
    User_FamilyApplyCheck: function (parm, callback) {
      parm = KOC.Lodash.extend({
        Family_ID: null,
        Type: null,//审批类型：1-申请成功，2-申请失败
        Admin_ID: null,
        Admin_RealName: null
      }, parm);
      if (!KOC.Lodash.includes([1, 2], parm.Type)) {
        callback(KOC.ReturnValue.New({
          hasError: true,
          message: "传入参数错误:Type"
        }));
        return;
      }
      var _Conn = null;
      KOC.Async.series([
        //读取公会表单
        function (callback) {
          DAL_Factory.User.Family_Info.Info(parm.Family_ID, function (retValue) {
            if (retValue.hasError) {
              callback(retValue);
              return;
            }
            if (!retValue.returnObject) {
              retValue.returnObject.hasError = true;
              retValue.returnObject.message = "公会信息不存在";
              callback(retValue);
              return;
            }
            if (retValue.returnObject.Status != 2) {
              retValue.returnObject.hasError = true;
              retValue.returnObject.message = "公会 ，不在审核状态中";
              callback(retValue);
              return;
            }
            parm.User_ID = retValue.returnObject.User_ID;
            callback();
          });
        },
        //读取用户信息
        function (callback) {
          DAL_Factory.User.User_Info.Info(parm.User_ID, function (retValue) {
            if (retValue.hasError) {
              callback(retValue);
              return;
            }
            if (!retValue.returnObject) {
              retValue.hasError = true;
              retValue.message = "用户信息不存在";
              callback(retValue);
              return;
            }
            if (retValue.returnObject.IsFamily == 1) {
              //用户已经有公会了
              retValue.hasError = true;
              retValue.message = "用户已经有公会了";
              callback(retValue);
              return;
            }
            //公会长是艺人
            parm.IsAnchor = retValue.returnObject.IsAnchor;
            callback();
          });
        },
        //开启事物
        function (callback) {
          KOC.MysqlHelper.TranOpen(Config.Mysql.DB.User, function (retValue) {
            if (retValue.hasError) {
              callback(retValue);
              return;
            }
            _Conn = retValue.returnObject;
            callback();
          });
        },
        //修改公会的状态信息
        function (callback) {
          DAL_Factory.User.Family_Info.Update_Status(_Conn, {
            Family_ID: parm.Family_ID,
            Status: parm.Type == 1 ? 0 : 3//：1-申请成功->0，2-申请失败->3
          }, function (retValue) {
            if (retValue.hasError) {
              callback(retValue);
              return;
            }
            if (retValue.returnObject !== 1) {
              retValue.hasError = true;
              retValue.message = "写入公会的状态信息出错，影响行(" + retValue.returnObject + ")";
              callback(retValue);
              return;
            }
            callback();
          });
        },
        //修改审核公会的管理员信息
        function (callback) {
          DAL_Factory.User.Family_Info.Update_ApproveAdmin(_Conn, {
            Family_ID: parm.Family_ID,
            Approve_Admin_ID: parm.Admin_ID,
            Approve_RealName: parm.Admin_RealName
          }, function (retValue) {
            if (retValue.hasError) {
              callback(retValue);
              return;
            }
            if (retValue.returnObject !== 1) {
              retValue.hasError = true;
              retValue.message = "修改审核公会的管理员信息出错，影响行(" + retValue.returnObject + ")";
              callback(retValue);
              return;
            }
            callback();
          });
        },
        //修改公会长的用户信息
        function (callback) {
          if (parm.Type == 2) {
            //申请失败
            callback();
            return;
          }
          DAL_Factory.User.User_Info.Update_IsFamily(_Conn, {
            User_ID: parm.User_ID,
            Status: true
          }, function (retValue) {
            if (retValue.hasError) {
              callback(retValue);
              return;
            }
            if (retValue.returnObject !== 1) {
              retValue.hasError = true;
              retValue.message = "写入公会长的用户信息出错，影响行(" + retValue.returnObject + ")";
              callback(retValue);
              return;
            }
            callback();
          });
        },
        //写入公会信息
        function (callback) {
          if (parm.Type == 2) {
            //申请失败
            callback();
            return;
          }
          DAL_Factory.User.User_Family.Insert(_Conn, {
            User_ID: parm.User_ID,
            Family_ID: parm.Family_ID,
            IsMaster: 1,
            RightCode: "",
            Create_IP: ""
          }, function (retValue) {
            if (retValue.hasError) {
              callback(retValue);
              return;
            }
            callback();
          });
        },
        //写入艺人信息
        function (callback) {
          if (parm.Type == 2) {
            //申请失败
            callback();
            return;
          }
          if (!parm.IsAnchor || parm.IsAnchor != 1) {
            //用户不是艺人
            callback();
            return;
          }
          DAL_Factory.User.User_Anchor.Update_FamilyID(_Conn, {
            User_ID: parm.User_ID,
            Family_ID: parm.Family_ID
          }, function (retValue) {
            if (retValue.hasError) {
              callback(retValue);
              return;
            }
            if (retValue.returnObject !== 1) {
              retValue.hasError = true;
              retValue.message = "写入艺人信息出错，影响行(" + retValue.returnObject + ")";
              callback(retValue);
              return;
            }
            callback();
          });
        },
        //修改公会艺人数量信息
        function (callback) {
          if (parm.IsAnchor != 1 || parm.Type != 1) {
            //用户不是艺人
            callback();
            return;
          }
          DAL_Factory.User.Family_Info.Update_AnchorNum(_Conn, {
            Family_ID: parm.Family_ID,
            Type: parm.Type//数量加一
          }, function (retValue) {
            if (retValue.hasError) {
              callback(retValue);
              return;
            }
            if (retValue.returnObject !== 1) {
              retValue.hasError = true;
              retValue.message = "写入公会艺人数量信息出错，影响行(" + retValue.returnObject + ")";
              callback(retValue);
              return;
            }
            callback();
          });
        }
      ], function (retValue) {
        if (retValue) {
          console.log("审核公会申请入驻失败:", retValue, parm);
          KOC.MysqlHelper.TranRollback(_Conn, function () {
            callback(retValue);
          });
          return;
        }
        KOC.MysqlHelper.TranCommit(_Conn, function (retValue) {
          if (retValue.hasError) {
            callback(retValue);
            return;
          }
          retValue = KOC.ReturnValue.New();
          retValue.returnObject = parm;
          callback(retValue);
        });
      });
    },
    //endregion
    //region User_FamilyBankTransction:公会帐户资金交易(豆)
    User_FamilyBankTransction: function (Conn, parm, callback) {
      if (!Conn) {
        callback(KOC.ReturnValue.New({
          hasError: false,
          message: "Connection is null"
        }));
        return;
      }
      parm = KOC.Lodash.extend({
        Family_ID: null,
        Related_User_ID: null,
        Related_User_NickName: null,
        Related_User_RealName: null,
        Related_Anchor_ID: null,
        Related_Anchor_NickName: null,
        Related_Anchor_RealName: null,
        Trade_Type: null,
        Trade_Flag: null,
        Trade_Amt: null,
        Trade_Order_No: null,
        Remark: null,
        Create_IP: null
      }, parm);
      if (parm.Trade_Amt <= 0) {
        callback(KOC.ReturnValue.New({
          hasError: false,
          message: "交易金额传入错误"
        }));
        return;
      }
      var _FamilyBankTransaction = CommonUtils.Family.BankTransaction.fnInfo(parm.Trade_Type);
      if (!_FamilyBankTransaction || _FamilyBankTransaction.Flag != parm.Trade_Flag) {
        callback(KOC.ReturnValue.New({
          hasError: false,
          message: "传入参数错误，交易记录数据不匹配"
        }));
        return;
      }
      parm.Trade_Type_Name = _FamilyBankTransaction.Name;
      KOC.Async.series([
        //资金操作
        function (callback) {
          DAL_Factory.User.Family_Info.Update_Bank(Conn, {
            Trade_Flag: parm.Trade_Flag,
            Trade_Amt: parm.Trade_Amt,
            Family_ID: parm.Family_ID
          }, function (retValue) {
            if (retValue.hasError) {
              callback(retValue);
              return;
            }
            if (retValue.returnObject !== 1) {
              var message = "修改公会资金数据出错，影响行(" + retValue.returnObject + ")";
              retValue.hasError = true;
              retValue.message = message;
              retValue.returnObject = parm;
              callback(retValue);
              return;
            }
            callback();
          });
        },
        //交易记录
        function (callback) {
          DAL_Factory.User.Family_Bank_Trade.Insert(Conn, {
            Family_ID: parm.Family_ID,
            Related_User_ID: parm.Related_User_ID,
            Related_User_NickName: parm.Related_User_NickName,
            Related_User_RealName: parm.Related_User_RealName,
            Related_Anchor_ID: parm.Related_Anchor_ID,
            Related_Anchor_NickName: parm.Related_Anchor_NickName,
            Related_Anchor_RealName: parm.Related_Anchor_RealName,
            Trade_Type: parm.Trade_Type,
            Trade_Type_Name: parm.Trade_Type_Name,
            Trade_Flag: parm.Trade_Flag,
            Trade_Amt: parm.Trade_Amt,
            Trade_Order_No: parm.Trade_Order_No,
            Remark: parm.Remark,
            Create_IP: parm.Create_IP
          }, function (retValue) {
            if (retValue.hasError) {
              callback(retValue);
              return;
            }
            if (retValue.returnObject !== 1) {
              retValue.hasError = true;
              retValue.message = "写入公会资金交易记录出错，影响行(" + retValue.returnObject + ")";
              callback(retValue);
              return;
            }
            callback();
          });
        }
      ], function (retValue) {
        if (retValue) {
          callback(retValue);
          return;
        }
        callback(KOC.ReturnValue.New());
      });
    },
    //endregion
    //region User_GuardianPurchase:守护购买
    User_GuardianPurchase: function (parm, callback) {
      parm = KOC.Lodash.extend({
        User_ID: null,
        User_ID_Guardian: null,
        Guardian_ID: null,
        Create_IP: null
      }, parm);
      if (parm.User_ID == parm.User_ID_Guardian) {
        callback(KOC.ReturnValue.New({
          hasError: true,
          message: "您不能给自己开通守护"
        }));
        return;
      }
      var _Conn = null;
      var _InsertUserAnchorGuardian = false;
      KOC.Async.series([
        //读取守护商品信息
        function (callback) {
          parm.GuardianInfo = CommonUtils.Commodity.Guardian.fnInfo(parm.Guardian_ID);
          if (!parm.GuardianInfo) {
            callback(KOC.ReturnValue.New({
              hasError: true,
              message: "没找到相应守护商品信息"
            }));
            return;
          }
          if (parm.GuardianInfo.Status != 0) {
            callback(KOC.ReturnValue.New({
              hasError: true,
              message: "此守护商品已被锁定"
            }));
            return;
          }
          if (parm.GuardianInfo.Commission_Family < 0
            || parm.GuardianInfo.Commission_Anchor < 0
            || parm.GuardianInfo.Commission_Family + parm.GuardianInfo.Commission_Anchor > 1) {
            callback(KOC.ReturnValue.New({
              hasError: true,
              message: "守护商品提成信息有误"
            }));
            return;
          }
          if (parm.GuardianInfo.Price <= 0) {
            callback(KOC.ReturnValue.New({
              hasError: true,
              message: "守护商品价格信息有误"
            }));
            return;
          }
          if (parm.GuardianInfo.EXP < 0
            || parm.GuardianInfo.EXP_Anchor < 0) {
            callback(KOC.ReturnValue.New({
              hasError: true,
              message: "守护商品经验信息有误"
            }));
            return;
          }
          parm.Commission_Guardian_Family = parm.GuardianInfo.Commission_Family;
          parm.Commission_Guardian_Anchor = parm.GuardianInfo.Commission_Anchor;
          parm.Order_Amt = parm.GuardianInfo.Price;
          callback();
        },
        //读取用户信息(守护人)
        function (callback) {
          DAL_Factory.User.User_Info.Info(parm.User_ID, function (retValue) {
            if (retValue.hasError) {
              callback(retValue);
              return;
            }
            if (!retValue.returnObject) {
              retValue.hasError = true;
              retValue.message = "无此用户信息";
              callback(retValue);
              return;
            }
            if (retValue.returnObject.Status != 0) {
              retValue.hasError = true;
              retValue.message = "此用户已被锁定";
              callback(retValue);
              return;
            }
            if (retValue.returnObject.Coin < parm.Order_Amt) {
              retValue.hasError = true;
              retValue.errorCode = -2;
              retValue.message = "用户金币不足";
              callback(retValue);
              return;
            }
            parm.User_ID = retValue.returnObject.User_ID;
            parm.User_NickName = retValue.returnObject.NickName;
            parm.User_RealName = retValue.returnObject.RealName;
            parm.User_Pomelo = retValue.returnObject.Pomelo;
            parm.User_EXP = retValue.returnObject.EXP + parm.GuardianInfo.EXP;
            parm.User_Coin = retValue.returnObject.Coin - parm.Order_Amt;
            callback();
          });
        },
        //读取用户信息(被守护人)
        function (callback) {
          DAL_Factory.User.User_Info.Info(parm.User_ID_Guardian, function (retValue) {
            if (retValue.hasError) {
              callback(retValue);
              return;
            }
            if (!retValue.returnObject) {
              retValue.hasError = true;
              retValue.message = "无此用户信息(被守护)";
              callback(retValue);
              return;
            }
            if (retValue.returnObject.Status != 0) {
              retValue.hasError = true;
              retValue.message = "此用户已被锁定(被守护)";
              callback(retValue);
              return;
            }
            if (!retValue.returnObject.IsAnchor) {
              retValue.hasError = true;
              retValue.message = "此用户不是艺人不能被守护";
              callback(retValue);
              return;
            }
            parm.User_ID_Guardian = retValue.returnObject.User_ID;
            parm.User_NickName_Guardian = retValue.returnObject.NickName;
            parm.User_RealName_Guardian = retValue.returnObject.RealName;
            parm.Anchor_Fans = retValue.returnObject.Fans;
            parm.Anchor_Attention = retValue.returnObject.Attention;
            parm.Anchor_Beans = retValue.returnObject.Beans;
            callback();
          });
        },
        //读取艺人信息
        function (callback) {
          DAL_Factory.User.User_Anchor.Info(parm.User_ID_Guardian, function (retValue) {
            if (retValue.hasError) {
              callback(retValue);
              return;
            }
            if (!retValue.returnObject) {
              retValue.hasError = true;
              retValue.message = "无此艺人信息";
              callback(retValue);
              return;
            }
            if (retValue.returnObject.Status != 0) {
              retValue.hasError = true;
              retValue.message = "此艺人已被锁定";
              callback(retValue);
              return;
            }
            parm.Live_Order_No = retValue.returnObject.Live_Order_No;
            parm.Commission_Anchor_Family = retValue.returnObject.Family_Commission;
            parm.Family_ID = retValue.returnObject.Family_ID;
            parm.Anchor_Pomelo = retValue.returnObject.Pomelo;
            parm.Anchor_EXP = retValue.returnObject.EXP + parm.GuardianInfo.EXP_Anchor;
            callback();
          });
        },
        //读取公会信息
        function (callback) {
          if (!parm.Family_ID || parm.Family_ID < 0) {
            parm.Family_ID = -1;
            parm.Family_Name = "";
            parm.Commission_Anchor_Family = 0;
            parm.Commission_Guardian_Family = 0;
            callback();
            return;
          }
          DAL_Factory.User.Family_Info.Info(parm.Family_ID, function (retValue) {
            if (retValue.hasError) {
              callback(retValue);
              return;
            }
            if (!retValue.returnObject) {
              retValue.hasError = true;
              retValue.message = "无此公会信息(被守护)";
              callback(retValue);
              return;
            }
            parm.Family_Name = retValue.returnObject.Family_Name;
            callback();
          });
        },
        //生成单据号
        function (callback) {
          DAL_Factory.Common.Order_No_Manage.Info(CommonUtils.OrderNo.Guardian.ID, function (retValue) {
            if (retValue.hasError) {
              callback(retValue);
              return;
            }
            if (!retValue.returnObject || !retValue.returnObject[0].Order_No) {
              retValue.hasError = true;
              retValue.message = "无此单据类型";
              callback(retValue);
              return;
            }
            parm.Order_No = retValue.returnObject[0].Order_No;
            callback();
          });
        },
        //开启事物
        function (callback) {
          KOC.MysqlHelper.TranOpen(Config.Mysql.DB.User, function (retValue) {
            if (retValue.hasError) {
              callback(retValue);
              return;
            }
            _Conn = retValue.returnObject;
            callback();
          });
        },
        //写入守护购买单
        function (callback) {
          //计算分成金额
          parm.Order_Amt_Anchor = KOC.StringUtils.ToIntPositive(parm.Order_Amt * parm.Commission_Guardian_Anchor);
          parm.Order_Amt_Family = KOC.StringUtils.ToIntPositive(parm.Order_Amt_Anchor * parm.Commission_Anchor_Family);
          parm.Order_Amt_Anchor -= parm.Order_Amt_Family;
          parm.Order_Amt_Family += KOC.StringUtils.ToIntPositive(parm.Order_Amt * parm.Commission_Guardian_Family);
          parm.Order_Amt_Platform = parm.Order_Amt - parm.Order_Amt_Family - parm.Order_Amt_Anchor;
          parm.Anchor_Beans += parm.Order_Amt_Anchor;
          DAL_Factory.User.Order_Guardian.Insert(_Conn, {
            Order_No: parm.Order_No,
            Live_Order_No: parm.Live_Order_No,
            User_ID: parm.User_ID,
            User_NickName: parm.User_NickName,
            User_RealName: parm.User_RealName,
            User_ID_Guardian: parm.User_ID_Guardian,
            User_NickName_Guardian: parm.User_NickName_Guardian,
            User_RealName_Guardian: parm.User_RealName_Guardian,
            Family_ID: parm.Family_ID,
            Family_Name: parm.Family_Name,
            Guardian_ID: parm.GuardianInfo.id,
            Guardian_Name: parm.GuardianInfo.Name,
            Guardian_Mode: parm.GuardianInfo.Mode,
            Guardian_Value: parm.GuardianInfo.Value,
            Commission_Guardian_Family: parm.Commission_Guardian_Family,
            Commission_Guardian_Anchor: parm.Commission_Guardian_Anchor,
            Commission_Anchor_Family: parm.Commission_Anchor_Family,
            Order_Amt: parm.Order_Amt,
            Order_Amt_Anchor: parm.Order_Amt_Anchor,
            Order_Amt_Family: parm.Order_Amt_Family,
            Order_Amt_Platform: parm.Order_Amt_Platform,
            Create_IP: parm.Create_IP
          }, function (retValue) {
            if (retValue.hasError) {
              callback(retValue);
              return;
            }
            if (retValue.returnObject !== 1) {
              retValue.hasError = true;
              retValue.message = "写入守护购买单出错，影响行(" + retValue.returnObject + ")";
              callback(retValue);
              return;
            }
            callback();
          });
        },
        //扣除购买人金额(币)
        function (callback) {
          DAL_Factory.Business.User_BankTransction(_Conn, {
            User_ID: parm.User_ID,
            Related_User_ID: parm.User_ID_Guardian,
            Related_User_NickName: parm.User_NickName_Guardian,
            Related_User_RealName: parm.User_RealName_Guardian,
            Related_Family_ID: parm.Family_ID,
            Related_Family_Name: parm.Family_Name,
            Trade_Currency: 1,
            Trade_Type: 302,
            Trade_Flag: -1,
            Trade_Amt: parm.Order_Amt,
            Trade_Order_No: parm.Order_No,
            Remark: "",
            Create_IP: parm.Create_IP
          }, function (retValue) {
            if (retValue.hasError) {
              callback(retValue);
              return;
            }
            callback();
          });
        },
        //增加购买人EXP
        function (callback) {
          if (parm.GuardianInfo.EXP == 0) {
            callback();
            return;
          }
          DAL_Factory.User.User_Info.Update_EXP(_Conn, {
            EXP: parm.GuardianInfo.EXP,
            User_ID: parm.User_ID
          }, function (retValue) {
            if (retValue.hasError) {
              callback(retValue);
              return;
            }
            if (retValue.returnObject !== 1) {
              retValue.hasError = true;
              retValue.message = "写入用户经验出错，影响行(" + retValue.returnObject + ")";
              callback(retValue);
              return;
            }
            callback();
          });
        },
        //增加被收护人金额(豆)
        function (callback) {
          if (parm.Order_Amt_Anchor == 0) {
            callback();
            return;
          }
          DAL_Factory.Business.User_BankTransction(_Conn, {
            User_ID: parm.User_ID_Guardian,
            Related_User_ID: parm.User_ID,
            Related_User_NickName: parm.User_NickName,
            Related_User_RealName: parm.User_RealName,
            Related_Family_ID: parm.Family_ID,
            Related_Family_Name: parm.Family_Name,
            Trade_Currency: 2,
            Trade_Type: 202,
            Trade_Flag: 1,
            Trade_Amt: parm.Order_Amt_Anchor,
            Trade_Order_No: parm.Order_No,
            Remark: "",
            Create_IP: parm.Create_IP
          }, function (retValue) {
            if (retValue.hasError) {
              callback(retValue);
              return;
            }
            callback();
          });
        },
        //增加艺人经验
        function (callback) {
          if (parm.GuardianInfo.EXP_Anchor == 0) {
            callback();
            return;
          }
          DAL_Factory.User.User_Anchor.Update_EXP(_Conn, {
            EXP: parm.GuardianInfo.EXP_Anchor,
            User_ID: parm.User_ID_Guardian
          }, function (retValue) {
            if (retValue.hasError) {
              callback(retValue);
              return;
            }
            if (retValue.returnObject !== 1) {
              retValue.hasError = true;
              retValue.message = "写入艺人经验出错，影响行(" + retValue.returnObject + ")";
              callback(retValue);
              return;
            }
            callback();
          });
        },
        //增加公会金额(豆)
        function (callback) {
          if (parm.Family_ID < 0
            || parm.Order_Amt_Family == 0) {
            callback();
            return;
          }
          DAL_Factory.Business.User_FamilyBankTransction(_Conn, {
            Family_ID: parm.Family_ID,
            Related_User_ID: parm.User_ID,
            Related_User_NickName: parm.User_NickName,
            Related_User_RealName: parm.User_RealName,
            Related_Anchor_ID: parm.User_ID_Guardian,
            Related_Anchor_NickName: parm.User_NickName_Guardian,
            Related_Anchor_RealName: parm.User_RealName_Guardian,
            Trade_Type: 202,
            Trade_Flag: 1,
            Trade_Amt: parm.Order_Amt_Family,
            Trade_Order_No: parm.Order_No,
            Remark: "",
            Create_IP: parm.Create_IP
          }, function (retValue) {
            if (retValue.hasError) {
              callback(retValue);
              return;
            }
            callback();
          });
        },
        //更新守护记录
        function (callback) {
          DAL_Factory.User.User_Anchor_Guardian.Update(_Conn, {
            User_ID: parm.User_ID,
            User_ID_Guardian: parm.User_ID_Guardian,
            Guardian_Mode: parm.GuardianInfo.Mode,
            Guardian_Value: parm.GuardianInfo.Value,
            Guardian_ID: parm.GuardianInfo.id,
            Guardian_Name: parm.GuardianInfo.Name
          }, function (retValue) {
            if (retValue.hasError) {
              callback(retValue);
              return;
            }
            if (retValue.returnObject !== 1) {
              _InsertUserAnchorGuardian = true;
              callback();
              return;
            }
            callback();
          });
        },
        //写入守护记录
        function (callback) {
          if (!_InsertUserAnchorGuardian) {
            callback();
            return;
          }
          DAL_Factory.User.User_Anchor_Guardian.Insert(_Conn, {
            User_ID: parm.User_ID,
            User_ID_Guardian: parm.User_ID_Guardian,
            Guardian_Mode: parm.GuardianInfo.Mode,
            Guardian_Value: parm.GuardianInfo.Value,
            Guardian_ID: parm.GuardianInfo.id,
            Guardian_Name: parm.GuardianInfo.Name,
            Create_IP: parm.Create_IP
          }, function (retValue) {
            if (retValue.hasError) {
              callback(retValue);
              return;
            }
            callback();
          });
        },
        //读取守护记录
        function (callback) {
          DAL_Factory.User.User_Anchor_Guardian.Info(_Conn, parm.User_ID, parm.User_ID_Guardian, function (retValue) {
            if (retValue.hasError) {
              callback(retValue);
              return;
            }
            if (!retValue.returnObject) {
              retValue.hasError = true;
              retValue.message = "没找到守护信息";
              callback(retValue);
              return;
            }
            parm.User_Guardian_Expire = retValue.returnObject.Guardian_Expire;
            callback();
          });
        },
        //更新直播单据
        function (callback) {
          if (!parm.Live_Order_No) {
            callback();
            return;
          }
          DAL_Factory.User.Order_Live.Update_Guardian(_Conn, {
            Order_No: parm.Live_Order_No,
            User_ID: parm.User_ID_Guardian,
            Guardian_Coin: parm.Order_Amt,
            Guardian_Beans_Anchor: parm.Order_Amt_Anchor,
            Guardian_Beans_Family: parm.Order_Amt_Family,
            Guardian_Beans_Platform: parm.Order_Amt_Platform
          }, function (retValue) {
            if (retValue.hasError) {
              callback(retValue);
              return;
            }
            if (retValue.returnObject !== 1) {
              retValue.hasError = true;
              retValue.message = "更新直播单数据出错，影响行(" + retValue.returnObject + ")";
              callback(retValue);
              return;
            }
            callback();
          });
        },
        //更新用户贡献
        function (callback) {
          DAL_Factory.Business.User_Contribution(_Conn, {
            User_ID: parm.User_ID,
            User_ID_Contribution: parm.User_ID_Guardian,
            Coin: parm.Order_Amt,
            Live: parm.Live_Order_No ? true : false
          }, function (retValue) {
            if (retValue.hasError) {
              callback(retValue);
              return;
            }
            callback();
          });
        },
        //提交事务
        function (callback) {
          KOC.MysqlHelper.TranCommit(_Conn, function (retValue) {
            _Conn = null;
            if (retValue.hasError) {
              callback(retValue);
              return;
            }
            callback();
          });
        },
        //更新艺人热度
        function (callback) {
          DAL_Factory.Business.User_AnchorHot({
            Type: "Guardin",
            Num: 1,
            Coin: parm.Order_Amt,
            Value: KOC.StringUtils.ToIntPositive(parm.GuardianInfo.Price * KOC.StringUtils.ToIntPositive(parm.GuardianInfo.Hot, 1) * CommonUtils.Anchor.Hot.Guardin),
            User_ID: parm.User_ID_Guardian
          }, function () {
            callback();
          });
        }
      ], function (retValue) {
        if (retValue) {
          console.log("守护购买失败:", retValue, parm);
          KOC.MysqlHelper.TranRollback(_Conn, function () {
            callback(retValue);
          });
          return;
        }
        callback(KOC.ReturnValue.New({
          returnObject: {
            Order_Amt: parm.Order_Amt,
            Order_Amt_Anchor: parm.Order_Amt_Anchor,
            Order_Amt_Family: parm.Order_Amt_Family,
            Order_Amt_Platform: parm.Order_Amt_Platform,
            User_ID: parm.User_ID,
            User_ID_Guardian: parm.User_ID_Guardian,
            User_Pomelo: parm.User_Pomelo,
            User_EXP: parm.User_EXP,
            User_Coin: parm.User_Coin,
            User_Guardian_Expire: parm.User_Guardian_Expire,
            Anchor_Beans: parm.Anchor_Beans,
            Anchor_Pomelo: parm.Anchor_Pomelo,
            Anchor_EXP: parm.Anchor_EXP,
            Anchor_Fans: parm.Anchor_Fans,
            Anchor_Attention: parm.Anchor_Attention,
            GuardianInfo: parm.GuardianInfo
          }
        }));
      });
    },
    //endregion
    //region User_VIPPurchase:VIP购买
    User_VIPPurchase: function (parm, callback) {
      parm = KOC.Lodash.extend({
        User_ID: null,
        VIP_ID: null,
        Create_IP: null
      }, parm);
      var _Conn = null;
      var _VIP_ID = KOC.StringUtils.ToInt(parm.VIP_ID);
      if (_VIP_ID > 0) {
        parm.VIP_ID = _VIP_ID;
      }
      KOC.Async.series([
        //读取VIP商品信息
        function (callback) {
          var _VIPInfo = CommonUtils.Commodity.VIP.fnInfo(parm.VIP_ID);
          if (!_VIPInfo) {
            callback(KOC.ReturnValue.New({
              hasError: true,
              message: "没找到相应VIP商品信息"
            }));
            return;
          }
          if (_VIPInfo.Status != 0) {
            callback(KOC.ReturnValue.New({
              hasError: true,
              message: "此VIP商品已被锁定"
            }));
            return;
          }
          if (_VIPInfo.Price <= 0) {
            callback(KOC.ReturnValue.New({
              hasError: true,
              message: "VIP商品价格信息有误"
            }));
            return;
          }
          if (_VIPInfo.EXP < 0) {
            callback(KOC.ReturnValue.New({
              hasError: true,
              message: "VIP商品经验信息有误"
            }));
            return;
          }
          parm.VIP_ID = _VIPInfo.id;
          parm.VIP_Name = _VIPInfo.Name;
          parm.VIP_Price = _VIPInfo.Price;
          parm.VIP_Mode = _VIPInfo.Mode;
          parm.VIP_Value = _VIPInfo.Value;
          parm.EXP = _VIPInfo.EXP;
          parm.Order_Amt = parm.VIP_Price;
          callback();
        },
        //读取用户信息
        function (callback) {
          DAL_Factory.User.User_Info.Info(parm.User_ID, function (retValue) {
            if (retValue.hasError) {
              callback(retValue);
              return;
            }
            if (!retValue.returnObject) {
              retValue.hasError = true;
              retValue.message = "无此用户信息";
              callback(retValue);
              return;
            }
            if (retValue.returnObject.Status != 0) {
              retValue.hasError = true;
              retValue.message = "此用户已被锁定";
              callback(retValue);
              return;
            }
            if (retValue.returnObject.Coin < parm.Order_Amt) {
              retValue.hasError = true;
              retValue.errorCode = -2;
              retValue.message = "用户金币不足";
              callback(retValue);
              return;
            }
            parm.User_ID = retValue.returnObject.User_ID;
            parm.User_NickName = retValue.returnObject.NickName;
            parm.User_RealName = retValue.returnObject.RealName;
            callback();
          });
        },
        //生成单据号
        function (callback) {
          DAL_Factory.Common.Order_No_Manage.Info(CommonUtils.OrderNo.VIP.ID, function (retValue) {
            if (retValue.hasError) {
              callback(retValue);
              return;
            }
            if (!retValue.returnObject || !retValue.returnObject[0].Order_No) {
              retValue.hasError = true;
              retValue.message = "无此单据类型";
              callback(retValue);
              return;
            }
            parm.Order_No = retValue.returnObject[0].Order_No;
            callback();
          });
        },
        //开启事物
        function (callback) {
          KOC.MysqlHelper.TranOpen(Config.Mysql.DB.User, function (retValue) {
            if (retValue.hasError) {
              callback(retValue);
              return;
            }
            _Conn = retValue.returnObject;
            callback();
          });
        },
        //写入VIP购买单
        function (callback) {
          DAL_Factory.User.Order_VIP.Insert(_Conn, {
            Order_No: parm.Order_No,
            User_ID: parm.User_ID,
            User_NickName: parm.User_NickName,
            User_RealName: parm.User_RealName,
            VIP_ID: parm.VIP_ID,
            VIP_Name: parm.VIP_Name,
            VIP_Mode: parm.VIP_Mode,
            VIP_Value: parm.VIP_Value,
            Order_Amt: parm.Order_Amt,
            Create_IP: parm.Create_IP
          }, function (retValue) {
            if (retValue.hasError) {
              callback(retValue);
              return;
            }
            if (retValue.returnObject !== 1) {
              retValue.hasError = true;
              retValue.message = "写入VIP购买单出错，影响行(" + retValue.returnObject + ")";
              callback(retValue);
              return;
            }
            callback();
          });
        },
        //扣除购买人金额(币)
        function (callback) {
          DAL_Factory.Business.User_BankTransction(_Conn, {
            User_ID: parm.User_ID,
            Related_User_ID: -1,
            Related_User_NickName: "",
            Related_User_RealName: "",
            Related_Family_ID: -1,
            Related_Family_Name: "",
            Trade_Currency: 1,
            Trade_Type: 303,
            Trade_Flag: -1,
            Trade_Amt: parm.Order_Amt,
            Trade_Order_No: parm.Order_No,
            Remark: "",
            Create_IP: parm.Create_IP
          }, function (retValue) {
            if (retValue.hasError) {
              callback(retValue);
              return;
            }
            callback();
          });
        },
        //增加购买人EXP
        function (callback) {
          if (parm.EXP == 0) {
            callback();
            return;
          }
          DAL_Factory.User.User_Info.Update_EXP(_Conn, {
            EXP: parm.EXP,
            User_ID: parm.User_ID
          }, function (retValue) {
            if (retValue.hasError) {
              callback(retValue);
              return;
            }
            if (retValue.returnObject !== 1) {
              retValue.hasError = true;
              retValue.message = "写入用户经验出错，影响行(" + retValue.returnObject + ")";
              callback(retValue);
              return;
            }
            callback();
          });
        },
        //更新用户VIP信息
        function (callback) {
          DAL_Factory.User.User_Info.Update_VIP(_Conn, {
            VIP_Mode: parm.VIP_Mode,
            VIP_Value: parm.VIP_Value,
            User_ID: parm.User_ID
          }, function (retValue) {
            if (retValue.hasError) {
              callback(retValue);
              return;
            }
            if (retValue.returnObject !== 1) {
              retValue.hasError = true;
              retValue.message = "更新用户VIP信息出错，影响行(" + retValue.returnObject + ")";
              callback(retValue);
              return;
            }
            callback();
          });
        }
      ], function (retValue) {
        if (retValue) {
          console.log("购买VIP失败:", retValue, parm);
          KOC.MysqlHelper.TranRollback(_Conn, function () {
            callback(retValue);
          });
          return;
        }
        KOC.MysqlHelper.TranCommit(_Conn, function (retValue) {
          if (retValue.hasError) {
            callback(retValue);
            return;
          }
          retValue = KOC.ReturnValue.New();
          retValue.returnObject = parm;
          callback(retValue);
        });
      });
    },
    //endregion
    //region User_MountsPurchase:座骑购买
    User_MountsPurchase: function (parm, callback) {
      parm = KOC.Lodash.extend({
        User_ID: null,
        Mounts_ID: null,
        Num: null,
        Create_IP: null
      }, parm);
      parm.Num = KOC.StringUtils.ToInt(parm.Num);
      if (parm.Num <= 0) {
        callback(KOC.ReturnValue.New({
          hasError: true,
          message: "购买数量必须大于0"
        }));
        return;
      }
      var _Mounts_ID = KOC.StringUtils.ToInt(parm.Mounts_ID);
      if (_Mounts_ID > 0) {
        parm.Mounts_ID = _Mounts_ID;
      }
      var _Conn = null;
      KOC.Async.series([
        //读取座骑商品信息
        function (callback) {
          var _MountsInfo = CommonUtils.Commodity.Mounts.fnInfo(parm.Mounts_ID);
          if (!_MountsInfo) {
            callback(KOC.ReturnValue.New({
              hasError: true,
              message: "没找到相应座骑商品信息"
            }));
            return;
          }
          if (_MountsInfo.Status != 0) {
            callback(KOC.ReturnValue.New({
              hasError: true,
              message: "此座骑商品已被锁定"
            }));
            return;
          }
          if (_MountsInfo.Price <= 0) {
            callback(KOC.ReturnValue.New({
              hasError: true,
              message: "座骑商品价格信息有误"
            }));
            return;
          }
          if (_MountsInfo.EXP < 0) {
            callback(KOC.ReturnValue.New({
              hasError: true,
              message: "座骑商品经验信息有误"
            }));
            return;
          }
          parm.Mounts_ID = _MountsInfo.id;
          parm.Mounts_Name = _MountsInfo.Name;
          parm.Mounts_Price = _MountsInfo.Price;
          parm.Mounts_Mode = _MountsInfo.Mode;
          parm.Mounts_Value = _MountsInfo.Value;
          parm.Mounts_UserLevel = _MountsInfo.UserLevel;
          parm.EXP = _MountsInfo.EXP;
          parm.Order_Amt = parm.Mounts_Price * parm.Num;
          callback();
        },
        //读取用户信息
        function (callback) {
          DAL_Factory.User.User_Info.Info(parm.User_ID, function (retValue) {
            if (retValue.hasError) {
              callback(retValue);
              return;
            }
            if (!retValue.returnObject) {
              retValue.hasError = true;
              retValue.message = "无此用户信息";
              callback(retValue);
              return;
            }
            if (retValue.returnObject.Status != 0) {
              retValue.hasError = true;
              retValue.message = "此用户已被锁定";
              callback(retValue);
              return;
            }
            if (retValue.returnObject.Level < parm.Mounts_UserLevel) {
              retValue.hasError = true;
              retValue.message = "用户等级不能购买此座骑";
              callback(retValue);
              return;
            }
            if (retValue.returnObject.Coin < parm.Order_Amt) {
              retValue.hasError = true;
              retValue.errorCode = -2;
              retValue.message = "用户金币不足";
              callback(retValue);
              return;
            }
            parm.User_ID = retValue.returnObject.User_ID;
            parm.User_NickName = retValue.returnObject.NickName;
            parm.User_RealName = retValue.returnObject.RealName;
            callback();
          });
        },
        //生成单据号
        function (callback) {
          DAL_Factory.Common.Order_No_Manage.Info(CommonUtils.OrderNo.Mounts.ID, function (retValue) {
            if (retValue.hasError) {
              callback(retValue);
              return;
            }
            if (!retValue.returnObject || !retValue.returnObject[0].Order_No) {
              retValue.hasError = true;
              retValue.message = "无此单据类型";
              callback(retValue);
              return;
            }
            parm.Order_No = retValue.returnObject[0].Order_No;
            callback();
          });
        },
        //开启事物
        function (callback) {
          KOC.MysqlHelper.TranOpen(Config.Mysql.DB.User, function (retValue) {
            if (retValue.hasError) {
              callback(retValue);
              return;
            }
            _Conn = retValue.returnObject;
            callback();
          });
        },
        //写入座骑购买单
        function (callback) {
          DAL_Factory.User.Order_Mounts.Insert(_Conn, {
            Order_No: parm.Order_No,
            User_ID: parm.User_ID,
            User_NickName: parm.User_NickName,
            User_RealName: parm.User_RealName,
            Mounts_ID: parm.Mounts_ID,
            Mounts_Name: parm.Mounts_Name,
            Mounts_Mode: parm.Mounts_Mode,
            Mounts_Value: parm.Mounts_Value,
            Mounts_Price: parm.Mounts_Price,
            Order_Num: parm.Num,
            Order_Amt: parm.Order_Amt,
            Create_IP: parm.Create_IP
          }, function (retValue) {
            if (retValue.hasError) {
              callback(retValue);
              return;
            }
            if (retValue.returnObject !== 1) {
              retValue.hasError = true;
              retValue.message = "写入座骑购买单出错，影响行(" + retValue.returnObject + ")";
              callback(retValue);
              return;
            }
            callback();
          });
        },
        //扣除购买人金额(币)
        function (callback) {
          DAL_Factory.Business.User_BankTransction(_Conn, {
            User_ID: parm.User_ID,
            Related_User_ID: -1,
            Related_User_NickName: "",
            Related_User_RealName: "",
            Related_Family_ID: -1,
            Related_Family_Name: "",
            Trade_Currency: 1,
            Trade_Type: 304,
            Trade_Flag: -1,
            Trade_Amt: parm.Order_Amt,
            Trade_Order_No: parm.Order_No,
            Remark: "",
            Create_IP: parm.Create_IP
          }, function (retValue) {
            if (retValue.hasError) {
              callback(retValue);
              return;
            }
            callback();
          });
        },
        //增加购买人EXP
        function (callback) {
          if (parm.EXP == 0) {
            callback();
            return;
          }
          DAL_Factory.User.User_Info.Update_EXP(_Conn, {
            EXP: parm.EXP,
            User_ID: parm.User_ID
          }, function (retValue) {
            if (retValue.hasError) {
              callback(retValue);
              return;
            }
            if (retValue.returnObject !== 1) {
              retValue.hasError = true;
              retValue.message = "写入用户经验出错，影响行(" + retValue.returnObject + ")";
              callback(retValue);
              return;
            }
            callback();
          });
        },
        //写入座骑信息
        function (callback) {
          DAL_Factory.User.User_Mounts.Insert(_Conn, {
            User_ID: parm.User_ID,
            Mounts_ID: parm.Mounts_ID,
            Mounts_Mode: parm.Mounts_Mode,
            Mounts_Value: parm.Mounts_Value * parm.Num,
            Mounts_Name: parm.Mounts_Name,
            Create_IP: parm.Create_IP
          }, function (retValue) {
            if (retValue.hasError) {
              callback(retValue);
              return;
            }
            callback();
          });
        }
      ], function (retValue) {
        if (retValue) {
          console.log("购买座骑失败:", retValue, parm);
          KOC.MysqlHelper.TranRollback(_Conn, function () {
            callback(retValue);
          });
          return;
        }
        KOC.MysqlHelper.TranCommit(_Conn, function (retValue) {
          if (retValue.hasError) {
            callback(retValue);
            return;
          }
          retValue = KOC.ReturnValue.New();
          retValue.returnObject = parm;
          callback(retValue);
        });
      });
    },
    //endregion
    //region User_MountsUpdate:用户更新坐骑
    User_MountsUpdate: function (parm, callback) {
      parm = KOC.Lodash.extend({
        User_ID: null,
        Mounts_ID: null,
        Create_IP: null
      }, parm);
      var _Mounts_ID = KOC.StringUtils.ToInt(parm.Mounts_ID);
      if (_Mounts_ID > 0) {
        parm.Mounts_ID = _Mounts_ID;
      }
      KOC.Async.series([
        //读取坐骑信息
        function (callback) {
          if (parm.Mounts_ID == "-1" || parm.Mounts_ID == -1) {
            callback();
            return;
          }
          DAL_Factory.User.User_Mounts.Info(parm.User_ID, parm.Mounts_ID, function (retValue) {
            if (retValue.hasError) {
              callback(retValue);
              return;
            }
            if (!retValue.returnObject) {
              retValue.hasError = true;
              retValue.message = "用户的坐骑信息不存在";
              callback(retValue);
              return;
            }
            if (retValue.returnObject.Mounts_ExpireStatus !== 0) {
              retValue.hasError = true;
              retValue.message = "用户的坐骑已过期";
              callback(retValue);
              return;
            }
            callback();
          });
        },
        //更新用户的坐骑信息
        function (callback) {
          DAL_Factory.User.User_Info.Update_Mount(parm, function (retValue) {
            if (retValue.hasError) {
              callback(retValue);
              return;
            }
            if (retValue.returnObject !== 1) {
              retValue.hasError = true;
              retValue.message = "更新用户的坐骑信息单出错，影响行(" + retValue.returnObject + ")";
              callback(retValue);
              return;
            }
            callback();
          });
        }
      ], function (retValue) {
        if (retValue) {
          console.log("更新坐骑失败:", retValue, parm);
          callback(retValue);
          return;
        }
        callback(KOC.ReturnValue.New({
          returnObject: parm
        }));
      });
    },
    //endregion
    //region User_GiftPurchase:礼物购买
    User_GiftPurchase: function (parm, callback) {
      parm = KOC.Lodash.extend({
        PurchaseMode: null, //购买模式 0:先使用包裹再购买 1:只购买 2:只使用包裹
        User_ID_Anchor: null,
        User_ID: null,
        User_ID_Gift: null,
        Gift_ID: null,
        Num: null,
        Create_IP: null
      }, parm);
      parm.Num = KOC.StringUtils.ToInt(parm.Num);
      if (parm.Num <= 0) {
        callback(KOC.ReturnValue.New({
          hasError: true,
          message: "购买数量必须大于0"
        }));
        return;
      }
      if (parm.User_ID == parm.User_ID_Gift) {
        callback(KOC.ReturnValue.New({
          hasError: true,
          message: "您不能送给自己礼物"
        }));
        return;
      }
      parm.PurchaseMode = KOC.StringUtils.ToIntPositive(parm.PurchaseMode);
      switch (parm.PurchaseMode) {
        case 0:
        case 1:
        case 2:
          break;
        default:
          parm.PurchaseMode = 0;
          break;
      }
      var _Conn = null;
      KOC.Async.series([
        //读取礼物商品信息
        function (callback) {
          parm.GiftInfo = CommonUtils.Commodity.Gift.fnInfo(parm.Gift_ID);
          if (!parm.GiftInfo) {
            callback(KOC.ReturnValue.New({
              hasError: true,
              message: "没找到相应礼物商品信息"
            }));
            return;
          }
          if (parm.GiftInfo.Status != 0) {
            callback(KOC.ReturnValue.New({
              hasError: true,
              message: "此礼物商品已被锁定"
            }));
            return;
          }
          if (parm.GiftInfo.Commission_Family < 0
            || parm.GiftInfo.Commission_Anchor < 0
            || parm.GiftInfo.Commission_Family + parm.GiftInfo.Commission_Anchor > 1) {
            callback(KOC.ReturnValue.New({
              hasError: true,
              message: "礼物商品提成信息有误"
            }));
            return;
          }
          if (parm.GiftInfo.Price < 0) {
            callback(KOC.ReturnValue.New({
              hasError: true,
              message: "礼物商品价格信息有误"
            }));
            return;
          }
          if (parm.GiftInfo.EXP < 0
            || parm.GiftInfo.EXP_Anchor < 0) {
            callback(KOC.ReturnValue.New({
              hasError: true,
              message: "礼物商品经验信息有误"
            }));
            return;
          }
          parm.Gift_ID = parm.GiftInfo.id;
          parm.Commission_Gift_Anchor = parm.GiftInfo.Commission_Anchor;
          parm.Commission_Gift_Family = parm.GiftInfo.Commission_Family;
          parm.Order_Amt = parm.GiftInfo.Price * parm.Num;
          callback();
        },
        //读取用户包裹商品信息
        function (callback) {
          if (parm.PurchaseMode == 1) {
            callback();
            return;
          }
          DAL_Factory.User.User_Package.Info(parm.User_ID, "Gift", parm.Gift_ID, function (retValue) {
            if (retValue.hasError) {
              callback(retValue);
              return;
            }
            if (parm.PurchaseMode == 2 && (!retValue.returnObject || retValue.returnObject.Num < parm.Num)) {
              retValue.hasError = true;
              retValue.message = "包裹里此物品不足";
              callback(retValue);
              return;
            }
            parm.PurchaseMode = (retValue.returnObject && retValue.returnObject.Num >= parm.Num) ? 2 : 1;
            callback();
          });
        },
        //其他逻辑判断
        function (callback) {
          if (parm.PurchaseMode == 1) {//购买礼物
            //购买礼物单价必须>0
            if (parm.GiftInfo.Price <= 0) {
              callback(KOC.ReturnValue.New({
                hasError: true,
                message: "礼物商品价格信息有误(1)"
              }));
              return;
            }
            //包裹限制礼物不允许购买
            if (parm.GiftInfo.PurchaseMode == 2) {
              callback(KOC.ReturnValue.New({
                hasError: true,
                message: "此礼物只能通过包裹赠送"
              }));
              return;
            }
          }
          callback();
        },
        //读取用户信息(购买人)
        function (callback) {
          DAL_Factory.User.User_Info.Info(parm.User_ID, function (retValue) {
            if (retValue.hasError) {
              callback(retValue);
              return;
            }
            if (!retValue.returnObject) {
              retValue.hasError = true;
              retValue.message = "无此用户信息";
              callback(retValue);
              return;
            }
            if (retValue.returnObject.Status != 0) {
              retValue.hasError = true;
              retValue.message = "此用户已被锁定";
              callback(retValue);
              return;
            }
            if (parm.PurchaseMode == 1 && retValue.returnObject.Coin < parm.Order_Amt) {
              retValue.hasError = true;
              retValue.errorCode = -2;
              retValue.message = "用户金币不足";
              callback(retValue);
              return;
            }
            if (parm.PurchaseMode == 1 && !retValue.returnObject.VIP && parm.GiftInfo.IsVIP) {
              retValue.hasError = true;
              retValue.errorCode = 1;
              retValue.message = "此商品只能VIP能购买";
              callback(retValue);
              return;
            }
            if (parm.PurchaseMode == 1 && parm.GiftInfo.UserLevel > 0 && parm.GiftInfo.UserLevel > retValue.returnObject.Level) {
              retValue.hasError = true;
              retValue.errorCode = 2;
              retValue.message = "您没有达到购买此礼物的最低等级";
              callback(retValue);
              return;
            }
            parm.User_ID = retValue.returnObject.User_ID;
            parm.User_NickName = retValue.returnObject.NickName;
            parm.User_RealName = retValue.returnObject.RealName;
            parm.User_Pomelo = retValue.returnObject.Pomelo;
            parm.User_EXP = retValue.returnObject.EXP + (parm.GiftInfo.EXP * parm.Num);
            parm.User_Coin = retValue.returnObject.Coin - (parm.PurchaseMode == 1 ? parm.Order_Amt : 0);
            callback();
          });
        },
        //读取用户信息(收礼人)
        function (callback) {
          DAL_Factory.User.User_Info.Info(parm.User_ID_Gift, function (retValue) {
            if (retValue.hasError) {
              callback(retValue);
              return;
            }
            if (!retValue.returnObject) {
              retValue.hasError = true;
              retValue.message = "无此用户信息(接收人)";
              callback(retValue);
              return;
            }
            if (retValue.returnObject.Status != 0) {
              retValue.hasError = true;
              retValue.message = "此用户已被锁定(接收人)";
              callback(retValue);
              return;
            }
            if (!retValue.returnObject.IsAnchor && parm.GiftInfo.IsGuardian) {
              retValue.hasError = true;
              retValue.message = "守护礼物只能送给您守护的艺人";
              callback(retValue);
              return;
            }
            parm.User_ID_Gift = retValue.returnObject.User_ID;
            parm.User_NickName_Gift = retValue.returnObject.NickName;
            parm.User_RealName_Gift = retValue.returnObject.RealName;
            parm.User_IsAnchor_Gift = retValue.returnObject.IsAnchor;
            parm.Anchor_Fans = retValue.returnObject.Fans;
            parm.Anchor_Attention = retValue.returnObject.Attention;
            parm.Anchor_Beans = retValue.returnObject.Beans;
            callback();
          });
        },
        //读取购买人守护信息(守护商品限制)
        function (callback) {
          if (parm.PurchaseMode == 2 || !parm.GiftInfo.IsGuardian) {
            callback();
            return;
          }
          DAL_Factory.User.User_Anchor_Guardian.Info(null, parm.User_ID, parm.User_ID_Gift, function (retValue) {
            if (retValue.hasError) {
              callback(retValue);
              return;
            }
            if (!retValue.returnObject || retValue.returnObject.Guardian_ExpireStatus !== 0) {
              retValue.hasError = true;
              retValue.message = "您不是此艺人的守护,不能购买守护礼物";
              callback(retValue);
              return;
            }
            callback();
          });
        },
        //读取艺人信息
        function (callback) {
          if (!parm.User_IsAnchor_Gift) {
            parm.Family_ID = -1;
            parm.Anchor_EXP = 0;
            callback();
            return;
          }
          DAL_Factory.User.User_Anchor.Info(parm.User_ID_Gift, function (retValue) {
            if (retValue.hasError) {
              callback(retValue);
              return;
            }
            if (!retValue.returnObject) {
              retValue.hasError = true;
              retValue.message = "无此艺人信息";
              callback(retValue);
              return;
            }
            if (retValue.returnObject.Status != 0) {
              parm.User_IsAnchor_Gift = 0;
              parm.Family_ID = -1;
              callback();
              return;
            }
            parm.Commission_Anchor_Family = retValue.returnObject.Family_Commission;
            parm.Family_ID = retValue.returnObject.Family_ID;
            parm.Anchor_Pomelo = retValue.returnObject.Pomelo;
            parm.Anchor_EXP = retValue.returnObject.EXP + (parm.GiftInfo.EXP_Anchor * parm.Num);
            parm.Live_Order_No = parm.User_ID_Anchor == parm.User_ID_Gift ? retValue.returnObject.Live_Order_No : null;
            callback();
          });
        },
        //读取艺人信息(房间艺人)
        function (callback) {
          if (parm.User_ID_Anchor == parm.User_ID_Gift) {
            callback();
            return;
          }
          DAL_Factory.User.User_Anchor.Info(parm.User_ID_Anchor, function (retValue) {
            if (retValue.hasError) {
              callback(retValue);
              return;
            }
            if (!retValue.returnObject) {
              retValue.hasError = true;
              retValue.message = "没有找到此房间艺人信息";
              callback(retValue);
              return;
            }
            if (retValue.returnObject.Status != 0) {
              retValue.hasError = true;
              retValue.message = "此房间艺人已被锁定";
              callback(retValue);
              return;
            }
            parm.Live_Order_No = retValue.returnObject.Live_Order_No;
            callback();
          });
        },
        //读取公会信息
        function (callback) {
          if (!parm.Family_ID || parm.Family_ID < 0) {
            parm.Family_ID = -1;
            parm.Family_Name = "";
            parm.Commission_Anchor_Family = 0;
            parm.Commission_Gift_Family = 0;
            callback();
            return;
          }
          DAL_Factory.User.Family_Info.Info(parm.Family_ID, function (retValue) {
            if (retValue.hasError) {
              callback(retValue);
              return;
            }
            if (!retValue.returnObject) {
              retValue.hasError = true;
              retValue.message = "无此公会信息(接收人)";
              callback(retValue);
              return;
            }
            parm.Family_Name = retValue.returnObject.Family_Name;
            callback();
          });
        },
        //生成单据号
        function (callback) {
          DAL_Factory.Common.Order_No_Manage.Info(CommonUtils.OrderNo.Gift.ID, function (retValue) {
            if (retValue.hasError) {
              callback(retValue);
              return;
            }
            if (!retValue.returnObject || !retValue.returnObject[0].Order_No) {
              retValue.hasError = true;
              retValue.message = "无此单据类型";
              callback(retValue);
              return;
            }
            parm.Order_No = retValue.returnObject[0].Order_No;
            callback();
          });
        },
        //开启事物
        function (callback) {
          KOC.MysqlHelper.TranOpen(Config.Mysql.DB.User, function (retValue) {
            if (retValue.hasError) {
              callback(retValue);
              return;
            }
            _Conn = retValue.returnObject;
            callback();
          });
        },
        //写入礼物购买单
        function (callback) {
          //计算分成金额
          parm.Order_Amt_Anchor = KOC.StringUtils.ToIntPositive(parm.Order_Amt * parm.Commission_Gift_Anchor);
          parm.Order_Amt_Family = KOC.StringUtils.ToIntPositive(parm.Order_Amt_Anchor * parm.Commission_Anchor_Family);
          parm.Order_Amt_Anchor -= parm.Order_Amt_Family;
          parm.Order_Amt_Family += KOC.StringUtils.ToIntPositive(parm.Order_Amt * parm.Commission_Gift_Family);
          parm.Order_Amt_Platform = parm.Order_Amt - parm.Order_Amt_Family - parm.Order_Amt_Anchor;
          DAL_Factory.User.Order_Gift.Insert(_Conn, {
            Order_No: parm.Order_No,
            Live_Order_No: parm.Live_Order_No,
            User_ID_Anchor: parm.User_ID_Anchor,
            User_ID: parm.User_ID,
            User_NickName: parm.User_NickName,
            User_RealName: parm.User_RealName,
            User_ID_Gift: parm.User_ID_Gift,
            User_NickName_Gift: parm.User_NickName_Gift,
            User_RealName_Gift: parm.User_RealName_Gift,
            Family_ID: parm.Family_ID,
            Family_Name: parm.Family_Name,
            Gift_ID: parm.GiftInfo.id,
            Gift_Name: parm.GiftInfo.Name,
            Gift_Price: parm.GiftInfo.Price,
            Commission_Gift_Family: parm.Commission_Gift_Family,
            Commission_Gift_Anchor: parm.Commission_Gift_Anchor,
            Commission_Anchor_Family: parm.Commission_Anchor_Family,
            Lucky: parm.GiftInfo.IsLucky,
            Order_Num: parm.Num,
            Order_Amt: parm.Order_Amt,
            Order_Amt_Anchor: parm.Order_Amt_Anchor,
            Order_Amt_Family: parm.Order_Amt_Family,
            Order_Amt_Platform: parm.Order_Amt_Platform,
            PurchaseMode: parm.PurchaseMode,
            IsTask: parm.GiftInfo.IsTask !== false,
            Create_IP: parm.Create_IP
          }, function (retValue) {
            if (retValue.hasError) {
              callback(retValue);
              return;
            }
            if (retValue.returnObject !== 1) {
              retValue.hasError = true;
              retValue.message = "写入礼物购买单出错，影响行(" + retValue.returnObject + ")";
              callback(retValue);
              return;
            }
            callback();
          });
        },
        //抽取幸运礼物
        function (callback) {
          if (!parm.GiftInfo.IsLucky) {
            parm.LuckyCoin = 0;
            callback();
            return;
          }
          DAL_Factory.User.Lucky_Gift_Info.Update_Proc(_Conn, parm.Order_No, function (retValue) {
            if (retValue.hasError) {
              callback(retValue);
              return;
            }
            if (!retValue.returnObject || (!retValue.returnObject.length && retValue.returnObject != 1)) {
              retValue.hasError = true;
              retValue.message = "抽取幸运礼物过程出错，请尽快来袭管理员";
              callback(retValue);
              return;
            }
            var multipleList = null;
            parm.LuckyMultipleList = [];
            if (!retValue.returnObject[0].MultipleList) {
              if (retValue.returnObject[0].LuckyCoin > 0) {
                retValue.hasError = true;
                retValue.message = "抽取幸运礼物过程出错，请尽快来袭管理员";
                callback(retValue);
                return;
              }
            } else {
              if (retValue.returnObject[0].MultipleList.length > 2) {
                multipleList = KOC.Lodash.groupBy(retValue.returnObject[0].MultipleList.split(","), KOC.StringUtils.ToInt);
                for (var key in multipleList) {
                  parm.LuckyMultipleList.push({
                    Multiple: KOC.StringUtils.ToInt(key),
                    Count: multipleList[key].length
                  });
                }
              } else {
                parm.LuckyMultipleList.push({
                  Multiple: KOC.StringUtils.ToInt(retValue.returnObject[0].MultipleList),
                  Count: 1
                });
              }
            }
            parm.LuckyCoin = retValue.returnObject[0].LuckyCoin;
            callback();
          });
        },
        //幸运礼物返金币
        function (callback) {
          if (parm.LuckyCoin == 0) {
            callback();
            return;
          }
          DAL_Factory.Business.User_BankTransction(_Conn, {
            User_ID: parm.User_ID,
            Related_User_ID: parm.User_ID_Gift,
            Related_User_NickName: parm.User_NickName_Gift,
            Related_User_RealName: parm.User_RealName_Gift,
            Related_Family_ID: parm.Family_ID,
            Related_Family_Name: parm.Family_Name,
            Trade_Currency: 1,
            Trade_Type: 109,
            Trade_Flag: 1,
            Trade_Amt: parm.LuckyCoin,
            Trade_Order_No: parm.Order_No,
            Remark: "幸运礼物-返金币",
            Create_IP: parm.Create_IP
          }, function (retValue) {
            if (retValue.hasError) {
              callback(retValue);
              return;
            }
            parm.User_Coin = parm.User_Coin + parm.LuckyCoin;
            callback();
          });
        },
        //扣除包裹物品
        function (callback) {
          if (parm.PurchaseMode != 2) {
            callback();
            return;
          }
          DAL_Factory.Business.User_PackageTransction(_Conn, {
            User_ID: parm.User_ID,
            Item_Type: "Gift",
            Item_ID: parm.Gift_ID,
            Trade_Type: 201,
            Trade_Flag: -1,
            Trade_Num: parm.Num,
            Trade_Order_No: parm.Order_No,
            Remark: "",
            Create_IP: parm.Create_IP
          }, function (retValue) {
            if (retValue.hasError) {
              retValue.message = "包裹物品不足";
              callback(retValue);
              return;
            }
            callback();
          });
        },
        //扣除购买人金额(币)
        function (callback) {
          if (parm.PurchaseMode != 1) {
            callback();
            return;
          }
          DAL_Factory.Business.User_BankTransction(_Conn, {
            User_ID: parm.User_ID,
            Related_User_ID: parm.User_ID_Gift,
            Related_User_NickName: parm.User_NickName_Gift,
            Related_User_RealName: parm.User_RealName_Gift,
            Related_Family_ID: parm.Family_ID,
            Related_Family_Name: parm.Family_Name,
            Trade_Currency: 1,
            Trade_Type: 301,
            Trade_Flag: -1,
            Trade_Amt: parm.Order_Amt,
            Trade_Order_No: parm.Order_No,
            Remark: "礼物购买",
            Create_IP: parm.Create_IP
          }, function (retValue) {
            if (retValue.hasError) {
              callback(retValue);
              return;
            }
            callback();
          });
        },
        //增加购买人EXP
        function (callback) {
          if (parm.GiftInfo.EXP == 0) {
            callback();
            return;
          }
          DAL_Factory.User.User_Info.Update_EXP(_Conn, {
            EXP: parm.GiftInfo.EXP * parm.Num,
            User_ID: parm.User_ID
          }, function (retValue) {
            if (retValue.hasError) {
              callback(retValue);
              return;
            }
            if (retValue.returnObject !== 1) {
              retValue.hasError = true;
              retValue.message = "写入用户经验出错，影响行(" + retValue.returnObject + ")";
              callback(retValue);
              return;
            }
            callback();
          });
        },
        //增加被接收人金额(豆)
        function (callback) {
          if (parm.Order_Amt_Anchor == 0) {
            callback();
            return;
          }
          DAL_Factory.Business.User_BankTransction(_Conn, {
            User_ID: parm.User_ID_Gift,
            Related_User_ID: parm.User_ID,
            Related_User_NickName: parm.User_NickName,
            Related_User_RealName: parm.User_RealName,
            Related_Family_ID: parm.Family_ID,
            Related_Family_Name: parm.Family_Name,
            Trade_Currency: 2,
            Trade_Type: 201,
            Trade_Flag: 1,
            Trade_Amt: parm.Order_Amt_Anchor,
            Trade_Order_No: parm.Order_No,
            Remark: "",
            Create_IP: parm.Create_IP
          }, function (retValue) {
            if (retValue.hasError) {
              callback(retValue);
              return;
            }
            callback();
          });
        },
        //增加艺人EXP
        function (callback) {
          if (!parm.User_IsAnchor_Gift || parm.GiftInfo.EXP_Anchor == 0) {
            callback();
            return;
          }
          DAL_Factory.User.User_Anchor.Update_EXP(_Conn, {
            EXP: parm.GiftInfo.EXP_Anchor * parm.Num,
            User_ID: parm.User_ID_Gift
          }, function (retValue) {
            if (retValue.hasError) {
              callback(retValue);
              return;
            }
            if (retValue.returnObject !== 1) {
              retValue.hasError = true;
              retValue.message = "写入艺人经验出错，影响行(" + retValue.returnObject + ")";
              callback(retValue);
              return;
            }
            callback();
          });
        },
        //增加公会金额(豆)
        function (callback) {
          if (parm.Family_ID < 0 || parm.Order_Amt_Family == 0) {
            callback();
            return;
          }
          DAL_Factory.Business.User_FamilyBankTransction(_Conn, {
            Family_ID: parm.Family_ID,
            Related_User_ID: parm.User_ID,
            Related_User_NickName: parm.User_NickName,
            Related_User_RealName: parm.User_RealName,
            Related_Anchor_ID: parm.User_ID_Gift,
            Related_Anchor_NickName: parm.User_NickName_Gift,
            Related_Anchor_RealName: parm.User_RealName_Gift,
            Trade_Type: 201,
            Trade_Flag: 1,
            Trade_Amt: parm.Order_Amt_Family,
            Trade_Order_No: parm.Order_No,
            Remark: "",
            Create_IP: parm.Create_IP
          }, function (retValue) {
            if (retValue.hasError) {
              callback(retValue);
              return;
            }
            callback();
          });
        },
        //更新直播单据
        function (callback) {
          if (!parm.Live_Order_No) {
            callback();
            return;
          }
          DAL_Factory.User.Order_Live.Update_Gift(_Conn, {
            Order_No: parm.Live_Order_No,
            User_ID: parm.User_ID,
            User_ID_Gift: parm.User_ID_Gift,
            User_ID_Anchor: parm.User_ID_Anchor,
            Gift_Num: parm.Num,
            Gift_Coin: parm.Order_Amt,
            Gift_Beans_User: parm.Order_Amt_Anchor,
            Gift_Beans_Family: parm.Order_Amt_Family,
            Gift_Beans_Platform: parm.Order_Amt_Platform
          }, function (retValue) {
            if (retValue.hasError) {
              callback(retValue);
              return;
            }
            if (retValue.returnObject !== 1) {
              retValue.hasError = true;
              retValue.message = "更新直播单数据出错，影响行(" + retValue.returnObject + ")";
              callback(retValue);
              return;
            }
            callback();
          });
        },
        //更新用户贡献
        function (callback) {
          if (parm.Order_Amt == 0) {
            callback();
            return;
          }
          DAL_Factory.Business.User_Contribution(_Conn, {
            User_ID: parm.User_ID,
            User_ID_Contribution: parm.User_ID_Gift,
            Coin: parm.Order_Amt,
            Live: parm.Live_Order_No ? true : false
          }, function (retValue) {
            if (retValue.hasError) {
              callback(retValue);
              return;
            }
            callback();
          });
        },
        //提交事务
        function (callback) {
          KOC.MysqlHelper.TranCommit(_Conn, function (retValue) {
            _Conn = null;
            if (retValue.hasError) {
              callback(retValue);
              return;
            }
            callback();
          });
        },
        //更新艺人热度
        function (callback) {
          if (!parm.User_IsAnchor_Gift) {
            callback();
            return;
          }
          DAL_Factory.Business.User_AnchorHot({
            Type: "Gift",
            Num: parm.Num,
            Coin: parm.Order_Amt,
            Value: KOC.StringUtils.ToIntPositive(parm.GiftInfo.Price * KOC.StringUtils.ToIntPositive(parm.GiftInfo.Hot, 1) * CommonUtils.Anchor.Hot.Gift),
            User_ID: parm.User_ID_Gift
          }, function () {
            callback();
          });
        },
        //任务提交
        function (callback) {
          switch (parm.Gift_ID) {
            case 58: //黄瓜
              parm.Task_ID = 1004;
              break;
            default:
              callback();
              return;
          }
          DAL_Factory.Business.User_Task({
            User_ID: parm.User_ID,
            User_NickName: parm.User_NickName,
            User_RealName: parm.User_RealName,
            Task_ID: parm.Task_ID,
            Task_Progress: parm.Num,
            Create_IP: parm.Create_IP
          }, function () {
            callback();
          });
        }
      ], function (retValue) {
        if (retValue) {
          console.log("礼物购买失败:", retValue, parm);
          KOC.MysqlHelper.TranRollback(_Conn, function () {
            callback(retValue);
          });
          return;
        }
        callback(KOC.ReturnValue.New({
          returnObject: {
            PurchaseMode: parm.PurchaseMode,
            Order_Amt: parm.Order_Amt,
            Order_Amt_Anchor: parm.Order_Amt_Anchor,
            Order_Amt_Family: parm.Order_Amt_Family,
            Order_Amt_Platform: parm.Order_Amt_Platform,
            User_ID: parm.User_ID,
            User_ID_Gift: parm.User_ID_Gift,
            User_ID_Anchor: parm.User_ID_Anchor,
            User_NickName: parm.User_NickName,
            User_NickName_Gift: parm.User_NickName_Gift,
            User_Pomelo: parm.User_Pomelo,
            User_EXP: parm.User_EXP,
            User_Coin: parm.User_Coin,
            Anchor_Beans: parm.Anchor_Beans,
            Anchor_Pomelo: parm.Anchor_Pomelo,
            Anchor_EXP: parm.Anchor_EXP,
            Anchor_Fans: parm.Anchor_Fans,
            Anchor_Attention: parm.Anchor_Attention,
            GiftNum: parm.Num,
            GiftInfo: parm.GiftInfo,
            LuckyCoin: parm.LuckyCoin,
            LuckyMultipleList: parm.LuckyMultipleList
          }
        }));
      });
    },
    //endregion
    //region User_GiftPond:礼物爆奖
    User_GiftPond: function (parm, callback) {
      parm = KOC.Lodash.extend({
        RoomID: null,
        Amt: null,
        Data: null,
        Create_IP: null
      }, parm);
      if (!parm.RoomID || parm.RoomID <= 0) {
        callback(KOC.ReturnValue.New({
          hasError: true,
          message: "传入参数错误:RoomID"
        }));
        return;
      }
      if (!parm.RoomID || parm.Amt <= 0) {
        callback(KOC.ReturnValue.New({
          hasError: true,
          message: "传入参数错误:Amt"
        }));
        return;
      }
      if (!parm.Data || parm.Data.length == 0) {
        callback(KOC.ReturnValue.New({
          hasError: true,
          message: "传入参数错误:Data"
        }));
        return;
      }
      var _Conn = null;
      KOC.Async.series([
        //读取艺人用户信息
        function (callback) {
          DAL_Factory.User.User_Info.Info(parm.RoomID, function (retValue) {
            if (retValue.hasError) {
              callback(retValue);
              return;
            }
            if (!retValue.returnObject) {
              retValue.hasError = true;
              retValue.message = "没有找到相关房间信息(用户)";
              callback(retValue);
              return;
            }
            if (!retValue.returnObject.IsAnchor) {
              retValue.hasError = true;
              retValue.message = "没有找到相关房间信息(非艺人)";
              callback(retValue);
              return;
            }
            parm.RoomID = retValue.returnObject.User_ID;
            parm.Anchor_NickName = retValue.returnObject.NickName;
            parm.Anchor_RealName = retValue.returnObject.RealName;
            callback();
          });
        },
        //读取艺人信息
        function (callback) {
          DAL_Factory.User.User_Anchor.Info(parm.RoomID, function (retValue) {
            if (retValue.hasError) {
              callback(retValue);
              return;
            }
            if (!retValue.returnObject) {
              retValue.hasError = true;
              retValue.message = "没有找到房间艺人信息";
              callback(retValue);
              return;
            }
            parm.Live_Order_No = retValue.returnObject.Live_Order_No;
            parm.Anchor_Family_ID = retValue.returnObject.Family_ID;
            callback();
          });
        },
        //读取艺人公会信息
        function (callback) {
          if (!parm.Anchor_Family_ID || parm.Anchor_Family_ID < 0) {
            parm.Anchor_Family_ID = -1;
            parm.Anchor_Family_Name = "";
            callback();
            return;
          }
          DAL_Factory.User.Family_Info.Info(parm.Anchor_Family_ID, function (retValue) {
            if (retValue.hasError) {
              callback(retValue);
              return;
            }
            if (!retValue.returnObject) {
              retValue.hasError = true;
              retValue.message = "无此公会信息";
              callback(retValue);
              return;
            }
            parm.Anchor_Family_Name = retValue.returnObject.Anchor_Family_Name;
            callback();
          });
        },
        //生成单据号
        function (callback) {
          DAL_Factory.Common.Order_No_Manage.Info(CommonUtils.OrderNo.Pond.ID, function (retValue) {
            if (retValue.hasError) {
              callback(retValue);
              return;
            }
            if (!retValue.returnObject || !retValue.returnObject[0].Order_No) {
              retValue.hasError = true;
              retValue.message = "无此单据类型";
              callback(retValue);
              return;
            }
            parm.Order_No = retValue.returnObject[0].Order_No;
            callback();
          });
        },
        //开启事物
        function (callback) {
          KOC.MysqlHelper.TranOpen(Config.Mysql.DB.User, function (retValue) {
            if (retValue.hasError) {
              callback(retValue);
              return;
            }
            _Conn = retValue.returnObject;
            callback();
          });
        },
        //更新直播单据
        function (callback) {
          if (!parm.Live_Order_No) {
            callback();
            return;
          }
          DAL_Factory.User.Order_Live.Update_GiftPond(_Conn, {
            Order_No: parm.Live_Order_No,
            User_ID: parm.RoomID,
            Gift_Pond_Coin: parm.Amt
          }, function (retValue) {
            if (retValue.hasError) {
              callback(retValue);
              return;
            }
            if (retValue.returnObject !== 1) {
              retValue.hasError = true;
              retValue.message = "更新直播单数据出错，影响行(" + retValue.returnObject + ")";
              callback(retValue);
              return;
            }
            callback();
          });
        },
        //增加用户金额
        function (callback) {
          parm.Amt_Real = 0;
          parm.DataList = [];
          KOC.Async.each(parm.Data, function (ThisValue, callback) {
            parm.DataList.push({
              Amt: ThisValue.Amt,
              User_ID: ThisValue.UserInfo.User_ID,
              NickName: ThisValue.UserInfo.NickName
            });
            parm.Amt_Real += ThisValue.Amt;
            DAL_Factory.Business.User_BankTransction(_Conn, {
              User_ID: ThisValue.User_ID || ThisValue.UserInfo.User_ID,
              Related_User_ID: parm.RoomID,
              Related_User_NickName: parm.Anchor_NickName,
              Related_User_RealName: parm.Anchor_RealName,
              Related_Family_ID: -1,
              Related_Family_Name: "",
              Trade_Currency: 1,
              Trade_Type: 103,
              Trade_Flag: 1,
              Trade_Amt: ThisValue.Amt,
              Trade_Order_No: parm.Order_No,
              Remark: "奖池爆奖",
              Create_IP: parm.Create_IP
            }, function (retValue) {
              if (retValue.hasError) {
                callback(retValue);
                return;
              }
              callback();
            });
          }, function (retValue) {
            if (retValue) {
              callback(retValue);
              return;
            }
            if (parm.Amt_Real != parm.Amt) {
              callback(KOC.ReturnValue.New({
                hasError: true,
                message: "用户爆奖金额与总金额不匹配( Amt:" + parm.Amt + " / Amt_Real:" + _parm.Amt_Real + " )"
              }));
              return;
            }
            callback(retValue);
          });
        },
        //写入爆奖单据
        function (callback) {
          DAL_Factory.User.Order_Pond.Insert(_Conn, {
            Order_No: parm.Order_No,
            User_ID: parm.RoomID,
            User_NickName: parm.Anchor_NickName,
            User_RealName: parm.Anchor_RealName,
            Family_ID: parm.Anchor_Family_ID,
            Family_Name: parm.Anchor_Family_Name,
            Live_Order_No: parm.Live_Order_No,
            Order_Num: parm.DataList.length,
            Order_Amt: parm.Amt,
            Detail: JSON.stringify(parm.DataList),
            Create_IP: parm.Create_IP
          }, function (retValue) {
            if (retValue.hasError) {
              callback(retValue);
              return;
            }
            callback();
          });
        }
      ], function (retValue) {
        if (retValue) {
          console.log("礼物开奖出错:", retValue, parm);
          KOC.MysqlHelper.TranRollback(_Conn, function () {
            callback(retValue);
          });
          return;
        }
        KOC.MysqlHelper.TranCommit(_Conn, function (retValue) {
          if (retValue.hasError) {
            callback(retValue);
            return;
          }
          retValue = KOC.ReturnValue.New();
          retValue.returnObject = parm;
          callback(retValue);
        });
      });
    },
    //endregion
    //region User_HornPurchase:喇叭购买
    User_HornPurchase: function (parm, callback) {
      parm = KOC.Lodash.extend({
        PurchaseMode: null, //购买模式 0:先使用包裹再购买 1:只购买 2:只使用包裹
        User_ID: null,
        User_ID_Anchor: null,
        Mode: null,
        Message: null,
        Create_IP: null
      }, parm);
      parm.PurchaseMode = KOC.StringUtils.ToIntPositive(parm.PurchaseMode);
      switch (parm.PurchaseMode) {
        case 0:
        case 1:
        case 2:
          break;
        default:
          parm.PurchaseMode = 0;
          break;
      }
      var _Conn = null;
      KOC.Async.series([
        //读取喇叭商品信息
        function (callback) {
          parm.HornInfo = CommonUtils.Commodity.Horn.fnInfo(parm.Mode);
          if (!parm.HornInfo) {
            callback(KOC.ReturnValue.New({
              hasError: true,
              message: "没找到相应喇叭商品信息"
            }));
            return;
          }
          if (parm.HornInfo.Status != 0) {
            callback(KOC.ReturnValue.New({
              hasError: true,
              message: "此喇叭商品已被锁定"
            }));
            return;
          }
          if (parm.HornInfo.Commission_Family < 0
            || parm.HornInfo.Commission_Anchor < 0
            || parm.HornInfo.Commission_Family + parm.HornInfo.Commission_Anchor > 1) {
            callback(KOC.ReturnValue.New({
              hasError: true,
              message: "喇叭商品提成信息有误"
            }));
            return;
          }
          if (parm.HornInfo.Price <= 0) {
            callback(KOC.ReturnValue.New({
              hasError: true,
              message: "喇叭商品价格信息有误"
            }));
            return;
          }
          if (parm.HornInfo.EXP < 0
            || parm.HornInfo.EXP_Anchor < 0) {
            callback(KOC.ReturnValue.New({
              hasError: true,
              message: "喇叭商品经验信息有误"
            }));
            return;
          }
          parm.Commission_Horn_Family = parm.HornInfo.Commission_Family;
          parm.Commission_Horn_Anchor = parm.HornInfo.Commission_Anchor;
          parm.Order_Amt = parm.HornInfo.Price;
          callback();
        },
        //读取用户包裹商品信息
        function (callback) {
          if (parm.PurchaseMode == 1) {
            callback();
            return;
          }
          DAL_Factory.User.User_Package.Info(parm.User_ID, "Horn", parm.Mode, function (retValue) {
            if (retValue.hasError) {
              callback(retValue);
              return;
            }
            if (parm.PurchaseMode == 2 && (!retValue.returnObject || retValue.returnObject.Num < 1)) {
              retValue.hasError = true;
              retValue.message = "包裹里此物品不足";
              callback(retValue);
              return;
            }
            parm.PurchaseMode = (retValue.returnObject && retValue.returnObject.Num >= 1) ? 2 : 1;
            callback();
          });
        },
        //读取用户信息(购买人)
        function (callback) {
          DAL_Factory.User.User_Info.Info(parm.User_ID, function (retValue) {
            if (retValue.hasError) {
              callback(retValue);
              return;
            }
            if (!retValue.returnObject) {
              retValue.hasError = true;
              retValue.message = "无此用户信息";
              callback(retValue);
              return;
            }
            if (retValue.returnObject.Status != 0) {
              retValue.hasError = true;
              retValue.message = "此用户已被锁定";
              callback(retValue);
              return;
            }
            if (parm.PurchaseMode == 1 && retValue.returnObject.Coin < parm.Order_Amt) {
              retValue.hasError = true;
              retValue.errorCode = -2;
              retValue.message = "用户金币不足";
              callback(retValue);
              return;
            }
            parm.User_ID = retValue.returnObject.User_ID;
            parm.User_NickName = retValue.returnObject.NickName;
            parm.User_RealName = retValue.returnObject.RealName;
            parm.User_Pomelo = retValue.returnObject.Pomelo;
            parm.User_EXP = retValue.returnObject.EXP + parm.HornInfo.EXP;
            parm.User_Coin = retValue.returnObject.Coin - (parm.PurchaseMode == 1 ? parm.Order_Amt : 0);
            callback();
          });
        },
        //读取用户信息(艺人)
        function (callback) {
          DAL_Factory.User.User_Info.Info(parm.User_ID_Anchor, function (retValue) {
            if (retValue.hasError) {
              callback(retValue);
              return;
            }
            if (!retValue.returnObject) {
              retValue.hasError = true;
              retValue.message = "无此用户信息(艺人)";
              callback(retValue);
              return;
            }
            if (retValue.returnObject.Status != 0) {
              retValue.hasError = true;
              retValue.message = "此用户已被锁定(艺人)";
              callback(retValue);
              return;
            }
            if (!retValue.returnObject.IsAnchor) {
              retValue.hasError = true;
              retValue.message = "此用户不是艺人";
              callback(retValue);
              return;
            }
            parm.User_ID_Anchor = retValue.returnObject.User_ID;
            parm.User_NickName_Anchor = retValue.returnObject.NickName;
            parm.User_RealName_Anchor = retValue.returnObject.RealName;
            parm.Anchor_Fans = retValue.returnObject.Fans;
            parm.Anchor_Attention = retValue.returnObject.Attention;
            parm.Anchor_Beans = retValue.returnObject.Beans;
            callback();
          });
        },
        //读取艺人信息
        function (callback) {
          DAL_Factory.User.User_Anchor.Info(parm.User_ID_Anchor, function (retValue) {
            if (retValue.hasError) {
              callback(retValue);
              return;
            }
            if (!retValue.returnObject) {
              retValue.hasError = true;
              retValue.message = "无此艺人信息";
              callback(retValue);
              return;
            }
            if (retValue.returnObject.Status != 0) {
              retValue.hasError = true;
              retValue.message = "此艺人已被锁定";
              callback(retValue);
              return;
            }
            parm.Family_ID = retValue.returnObject.Family_ID;
            parm.Live_Order_No = retValue.returnObject.Live_Order_No;
            parm.Commission_Anchor_Family = retValue.returnObject.Family_Commission;
            parm.Anchor_Pomelo = retValue.returnObject.Pomelo;
            parm.Anchor_EXP = retValue.returnObject.EXP + parm.HornInfo.EXP_Anchor;
            callback();
          });
        },
        //读取公会信息
        function (callback) {
          if (!parm.Family_ID || parm.Family_ID < 0) {
            parm.Family_ID = -1;
            parm.Family_Name = "";
            parm.Commission_Anchor_Family = 0;
            parm.Commission_Horn_Family = 0;
            callback();
            return;
          }
          DAL_Factory.User.Family_Info.Info(parm.Family_ID, function (retValue) {
            if (retValue.hasError) {
              callback(retValue);
              return;
            }
            if (!retValue.returnObject) {
              retValue.hasError = true;
              retValue.message = "无此公会信息(艺人)";
              callback(retValue);
              return;
            }
            parm.Family_Name = retValue.returnObject.Family_Name;
            callback();
          });
        },
        //生成单据号
        function (callback) {
          DAL_Factory.Common.Order_No_Manage.Info(CommonUtils.OrderNo.Horn.ID, function (retValue) {
            if (retValue.hasError) {
              callback(retValue);
              return;
            }
            if (!retValue.returnObject || !retValue.returnObject[0].Order_No) {
              retValue.hasError = true;
              retValue.message = "无此单据类型";
              callback(retValue);
              return;
            }
            parm.Order_No = retValue.returnObject[0].Order_No;
            callback();
          });
        },
        //开启事物
        function (callback) {
          KOC.MysqlHelper.TranOpen(Config.Mysql.DB.User, function (retValue) {
            if (retValue.hasError) {
              callback(retValue);
              return;
            }
            _Conn = retValue.returnObject;
            callback();
          });
        },
        //写入喇叭购买单
        function (callback) {
          //计算分成金额
          parm.Order_Amt_Anchor = KOC.StringUtils.ToIntPositive(parm.Order_Amt * parm.Commission_Horn_Anchor);
          parm.Order_Amt_Family = KOC.StringUtils.ToIntPositive(parm.Order_Amt_Anchor * parm.Commission_Anchor_Family);
          parm.Order_Amt_Anchor -= parm.Order_Amt_Family;
          parm.Order_Amt_Family += KOC.StringUtils.ToIntPositive(parm.Order_Amt * parm.Commission_Horn_Family);
          parm.Order_Amt_Platform = parm.Order_Amt - parm.Order_Amt_Family - parm.Order_Amt_Anchor;
          DAL_Factory.User.Order_Horn.Insert(_Conn, {
            Order_No: parm.Order_No,
            Live_Order_No: parm.Live_Order_No,
            Horn_Mode: parm.HornInfo.Mode,
            Horn_Message: parm.Message,
            User_ID: parm.User_ID,
            User_NickName: parm.User_NickName,
            User_RealName: parm.User_RealName,
            User_ID_Anchor: parm.User_ID_Anchor,
            User_NickName_Anchor: parm.User_NickName_Anchor,
            User_RealName_Anchor: parm.User_RealName_Anchor,
            Family_ID: parm.Family_ID,
            Family_Name: parm.Family_Name,
            Commission_Horn_Family: parm.Commission_Horn_Family,
            Commission_Horn_Anchor: parm.Commission_Horn_Anchor,
            Commission_Anchor_Family: parm.Commission_Anchor_Family,
            Order_Amt: parm.Order_Amt,
            Order_Amt_Anchor: parm.Order_Amt_Anchor,
            Order_Amt_Family: parm.Order_Amt_Family,
            Order_Amt_Platform: parm.Order_Amt_Platform,
            PurchaseMode: parm.PurchaseMode,
            Create_IP: parm.Create_IP
          }, function (retValue) {
            if (retValue.hasError) {
              callback(retValue);
              return;
            }
            if (retValue.returnObject !== 1) {
              retValue.hasError = true;
              retValue.message = "写入喇叭购买单出错，影响行(" + retValue.returnObject + ")";
              callback(retValue);
              return;
            }
            callback();
          });
        },
        //扣除包裹物品
        function (callback) {
          if (parm.PurchaseMode != 2) {
            callback();
            return;
          }
          DAL_Factory.Business.User_PackageTransction(_Conn, {
            User_ID: parm.User_ID,
            Item_Type: "Horn",
            Item_ID: parm.Mode,
            Trade_Type: 201,
            Trade_Flag: -1,
            Trade_Num: 1,
            Trade_Order_No: parm.Order_No,
            Remark: "",
            Create_IP: parm.Create_IP
          }, function (retValue) {
            if (retValue.hasError) {
              retValue.message = "包裹物品不足";
              callback(retValue);
              return;
            }
            callback();
          });
        },
        //扣除购买人金额(币)
        function (callback) {
          if (parm.PurchaseMode != 1) {
            callback();
            return;
          }
          DAL_Factory.Business.User_BankTransction(_Conn, {
            User_ID: parm.User_ID,
            Related_User_ID: parm.User_ID_Anchor,
            Related_User_NickName: parm.User_NickName_Anchor,
            Related_User_RealName: parm.User_RealName_Anchor,
            Related_Family_ID: parm.Family_ID,
            Related_Family_Name: parm.Family_Name,
            Trade_Currency: 1,
            Trade_Type: 305,
            Trade_Flag: -1,
            Trade_Amt: parm.Order_Amt,
            Trade_Order_No: parm.Order_No,
            Remark: "",
            Create_IP: parm.Create_IP
          }, function (retValue) {
            if (retValue.hasError) {
              callback(retValue);
              return;
            }
            callback();
          });
        },
        //增加购买人EXP
        function (callback) {
          if (parm.HornInfo.EXP == 0) {
            callback();
            return;
          }
          DAL_Factory.User.User_Info.Update_EXP(_Conn, {
            EXP: parm.HornInfo.EXP,
            User_ID: parm.User_ID
          }, function (retValue) {
            if (retValue.hasError) {
              callback(retValue);
              return;
            }
            if (retValue.returnObject !== 1) {
              retValue.hasError = true;
              retValue.message = "写入用户经验出错，影响行(" + retValue.returnObject + ")";
              callback(retValue);
              return;
            }
            callback();
          });
        },
        //增加艺人金额(豆)
        function (callback) {
          if (parm.Order_Amt_Anchor == 0) {
            callback();
            return;
          }
          DAL_Factory.Business.User_BankTransction(_Conn, {
            User_ID: parm.User_ID_Anchor,
            Related_User_ID: parm.User_ID,
            Related_User_NickName: parm.User_NickName,
            Related_User_RealName: parm.User_RealName,
            Related_Family_ID: parm.Family_ID,
            Related_Family_Name: parm.Family_Name,
            Trade_Currency: 2,
            Trade_Type: 203,
            Trade_Flag: 1,
            Trade_Amt: parm.Order_Amt_Anchor,
            Trade_Order_No: parm.Order_No,
            Remark: "",
            Create_IP: parm.Create_IP
          }, function (retValue) {
            if (retValue.hasError) {
              callback(retValue);
              return;
            }
            callback();
          });
        },
        //增加艺人经验
        function (callback) {
          if (parm.HornInfo.EXP_Anchor == 0) {
            callback();
            return;
          }
          DAL_Factory.User.User_Anchor.Update_EXP(_Conn, {
            EXP: parm.HornInfo.EXP_Anchor,
            User_ID: parm.User_ID_Anchor
          }, function (retValue) {
            if (retValue.hasError) {
              callback(retValue);
              return;
            }
            if (retValue.returnObject !== 1) {
              retValue.hasError = true;
              retValue.message = "写入艺人经验出错，影响行(" + retValue.returnObject + ")";
              callback(retValue);
              return;
            }
            callback();
          });
        },
        //增加公会金额(豆)
        function (callback) {
          if (parm.Family_ID < 0 || parm.Order_Amt_Family == 0) {
            callback();
            return;
          }
          DAL_Factory.Business.User_FamilyBankTransction(_Conn, {
            Family_ID: parm.Family_ID,
            Related_User_ID: parm.User_ID,
            Related_User_NickName: parm.User_NickName,
            Related_User_RealName: parm.User_RealName,
            Related_Anchor_ID: parm.User_ID_Anchor,
            Related_Anchor_NickName: parm.User_NickName_Anchor,
            Related_Anchor_RealName: parm.User_RealName_Anchor,
            Trade_Type: 203,
            Trade_Flag: 1,
            Trade_Amt: parm.Order_Amt_Family,
            Trade_Order_No: parm.Order_No,
            Remark: "",
            Create_IP: parm.Create_IP
          }, function (retValue) {
            if (retValue.hasError) {
              callback(retValue);
              return;
            }
            callback();
          });
        },
        //更新直播单据
        function (callback) {
          if (!parm.Live_Order_No) {
            callback();
            return;
          }
          DAL_Factory.User.Order_Live.Update_Horn(_Conn, {
            Order_No: parm.Live_Order_No,
            User_ID: parm.User_ID_Anchor,
            Horn_Coin: parm.Order_Amt,
            Horn_Beans_Anchor: parm.Order_Amt_Anchor,
            Horn_Beans_Family: parm.Order_Amt_Family,
            Horn_Beans_Platform: parm.Order_Amt_Platform
          }, function (retValue) {
            if (retValue.hasError) {
              callback(retValue);
              return;
            }
            if (retValue.returnObject !== 1) {
              retValue.hasError = true;
              retValue.message = "更新直播单数据出错，影响行(" + retValue.returnObject + ")";
              callback(retValue);
              return;
            }
            callback();
          });
        },
        //更新用户贡献
        function (callback) {
          DAL_Factory.Business.User_Contribution(_Conn, {
            User_ID: parm.User_ID,
            User_ID_Contribution: parm.User_ID_Anchor,
            Coin: parm.Order_Amt,
            Live: parm.Live_Order_No ? true : false
          }, function (retValue) {
            if (retValue.hasError) {
              callback(retValue);
              return;
            }
            callback();
          });
        },
        //提交事务
        function (callback) {
          KOC.MysqlHelper.TranCommit(_Conn, function (retValue) {
            _Conn = null;
            if (retValue.hasError) {
              callback(retValue);
              return;
            }
            callback();
          });
        },
        //更新艺人热度
        function (callback) {
          DAL_Factory.Business.User_AnchorHot({
            Type: "Horn",
            Coin: parm.Order_Amt,
            Value: KOC.StringUtils.ToIntPositive(parm.HornInfo.Price * KOC.StringUtils.ToIntPositive(parm.HornInfo.Hot, 1) * CommonUtils.Anchor.Hot.Horn),
            User_ID: parm.User_ID_Anchor
          }, function () {
            callback();
          });
        }
      ], function (retValue) {
        if (retValue) {
          console.log("购买喇叭失败:", retValue, parm);
          KOC.MysqlHelper.TranRollback(_Conn, function () {
            callback(retValue);
          });
          return;
        }
        callback(KOC.ReturnValue.New({
          returnObject: {
            PurchaseMode: parm.PurchaseMode,
            Order_Amt: parm.Order_Amt,
            Order_Amt_Anchor: parm.Order_Amt_Anchor,
            Order_Amt_Family: parm.Order_Amt_Family,
            Order_Amt_Platform: parm.Order_Amt_Platform,
            User_ID: parm.User_ID,
            User_ID_Anchor: parm.User_ID_Anchor,
            User_Pomelo: parm.User_Pomelo,
            User_EXP: parm.User_EXP,
            User_Coin: parm.User_Coin,
            Anchor_Beans: parm.Anchor_Beans,
            Anchor_Pomelo: parm.Anchor_Pomelo,
            Anchor_EXP: parm.Anchor_EXP,
            Anchor_Fans: parm.Anchor_Fans,
            Anchor_Attention: parm.Anchor_Attention,
            HornInfo: parm.HornInfo
          }
        }));
      });
    },
    //endregion
    //region User_PomeloGet:星星领取
    User_PomeloGet: function (parm, callback) {
      parm = KOC.Lodash.extend({
        User_ID: null
      }, parm);
      KOC.Async.series([
        //读取用户信息
        function (callback) {
          DAL_Factory.User.User_Info.Info(parm.User_ID, function (retValue) {
            if (retValue.hasError) {
              callback(retValue);
              return;
            }
            if (!retValue.returnObject) {
              retValue.hasError = true;
              retValue.message = "无此用户信息";
              callback(retValue);
              return;
            }
            if (retValue.returnObject.Status != 0) {
              retValue.hasError = true;
              retValue.message = "此用户已被锁定";
              callback(retValue);
              return;
            }
            if (KOC.Moment().diff(KOC.Moment(retValue.returnObject.Pomelo_Get_Date), "minutes") < CommonUtils.Commodity.Pomelo.Interval) {
              retValue.hasError = true;
              retValue.errorCode = 1;
              retValue.message = "您刚领过星星,过一会再领吧";
              callback(retValue);
              return;
            }
            if (retValue.returnObject.Pomelo >= 99) {
              retValue.hasError = true;
              retValue.errorCode = 2;
              retValue.message = "您最多只能累积99个星星。";
              callback(retValue);
              return;
            }
            parm.MAXToday = CommonUtils.Commodity.Pomelo.BaseNum;
            if (retValue.returnObject.VIP) {
              parm.MAXToday += 10;
            }
            if (retValue.returnObject.Level >= 10) {
              parm.MAXToday += 10;
            }
            if (retValue.returnObject.Level >= 19) {
              parm.MAXToday += 10;
            }
            if (retValue.returnObject.Level >= 28) {
              parm.MAXToday += 10;
            }
            parm.NumToday = retValue.returnObject.Pomelo_Get_NumToday;
            if (!retValue.returnObject.Pomelo_Get_Date
              || KOC.Moment().format("YYYYMMDD") != KOC.Moment(retValue.returnObject.Pomelo_Get_Date).format("YYYYMMDD")) {
              parm.NumToday = 0;
            }
            if (parm.NumToday >= parm.MAXToday) {
              retValue.hasError = true;
              retValue.errorCode = 2;
              retValue.message = "您每天只能领取" + parm.MAXToday + "个星星,今天已经领完了。";
              callback(retValue);
              return;
            }
            parm.NumToday++;
            parm.Pomelo = retValue.returnObject.Pomelo + 1;
            callback();
          });
        },
        //领取星星
        function (callback) {
          DAL_Factory.User.User_Info.Update_PomeloGet({
            MAXToday: parm.MAXToday,
            User_ID: parm.User_ID
          }, function (retValue) {
            if (retValue.hasError) {
              callback(retValue);
              return;
            }
            if (retValue.returnObject !== 1) {
              retValue.hasError = true;
              retValue.message = "写入用户星星数量出错，影响行(" + retValue.returnObject + ")";
              callback(retValue);
              return;
            }
            callback();
          });
        }
      ], function (retValue) {
        if (retValue) {
          callback(retValue);
          return;
        }
        callback(KOC.ReturnValue.New({
          returnObject: {
            User_ID: parm.User_ID,
            Pomelo: parm.Pomelo,
            MAXToday: parm.MAXToday,
            NumToday: parm.NumToday
          }
        }));
      });
    },
    //endregion
    //region User_PomeloPresent:星星赠送
    User_PomeloPresent: function (parm, callback) {
      parm = KOC.Lodash.extend({
        User_ID: null,
        User_ID_Anchor: null,
        Num: null,
        Create_IP: null
      }, parm);
      if (!parm.Num || parm.Num <= 0) {
        callback(KOC.ReturnValue.New({
          hasError: true,
          message: "赠送数量错误"
        }));
        return;
      }
      if (parm.User_ID == parm.User_ID_Anchor) {
        callback(KOC.ReturnValue.New({
          hasError: true,
          message: "您不能送给自己星星"
        }));
        return;
      }
      if (!CommonUtils.Commodity.Pomelo) {
        callback(KOC.ReturnValue.New({
          hasError: true,
          message: "星星设置错误,请联系管理员"
        }));
        return;
      }
      parm.EXP = CommonUtils.Commodity.Pomelo.EXP || 0;
      parm.EXP_Anchor = CommonUtils.Commodity.Pomelo.EXP_Anchor || 0;
      if (parm.EXP < 0 || parm.EXP_Anchor < 0) {
        callback(KOC.ReturnValue.New({
          hasError: true,
          message: "星星经验设置错误,请联系管理员"
        }));
        return;
      }
      var _Conn = null;
      KOC.Async.series([
        //读取用户信息(赠送人)
        function (callback) {
          DAL_Factory.User.User_Info.Info(parm.User_ID, function (retValue) {
            if (retValue.hasError) {
              callback(retValue);
              return;
            }
            if (!retValue.returnObject) {
              retValue.hasError = true;
              retValue.message = "无此用户信息";
              callback(retValue);
              return;
            }
            if (retValue.returnObject.Status != 0) {
              retValue.hasError = true;
              retValue.message = "此用户已被锁定";
              callback(retValue);
              return;
            }
            if (retValue.returnObject.Pomelo < parm.Num) {
              retValue.hasError = true;
              retValue.errorCode = 1;
              retValue.message = "您已经没有星星了";
              callback(retValue);
              return;
            }
            parm.User_ID = retValue.returnObject.User_ID;
            parm.User_NickName = retValue.returnObject.NickName;
            parm.User_RealName = retValue.returnObject.RealName;
            parm.User_Pomelo = retValue.returnObject.Pomelo - parm.Num;
            parm.User_EXP = retValue.returnObject.EXP + (parm.EXP * parm.Num);
            callback();
          });
        },
        //读取用户信息(接收星星艺人)
        function (callback) {
          DAL_Factory.User.User_Info.Info(parm.User_ID_Anchor, function (retValue) {
            if (retValue.hasError) {
              callback(retValue);
              return;
            }
            if (!retValue.returnObject) {
              retValue.hasError = true;
              retValue.message = "无此用户信息(艺人)";
              callback(retValue);
              return;
            }
            if (retValue.returnObject.Status != 0) {
              retValue.hasError = true;
              retValue.message = "此用户已被锁定(艺人)";
              callback(retValue);
              return;
            }
            if (!retValue.returnObject.IsAnchor) {
              retValue.hasError = true;
              retValue.message = "此用户不是艺人不能被赠送星星";
              callback(retValue);
              return;
            }
            parm.Anchor_Fans = retValue.returnObject.Fans;
            parm.Anchor_Attention = retValue.returnObject.Attention;
            callback();
          });
        },
        //读取艺人信息(接收星星艺人)
        function (callback) {
          DAL_Factory.User.User_Anchor.Info(parm.User_ID_Anchor, function (retValue) {
            if (retValue.hasError) {
              callback(retValue);
              return;
            }
            if (!retValue.returnObject) {
              retValue.hasError = true;
              retValue.message = "无此艺人信息";
              callback(retValue);
              return;
            }
            if (retValue.returnObject.Status != 0) {
              retValue.hasError = true;
              retValue.message = "此艺人已被锁定";
              callback(retValue);
              return;
            }
            parm.Anchor_Pomelo = retValue.returnObject.Pomelo + parm.Num;
            parm.Anchor_EXP = retValue.returnObject.EXP + (parm.EXP_Anchor * parm.Num);
            parm.Live_Order_No = retValue.returnObject.Live_Order_No;
            callback();
          });
        },
        //开启事物
        function (callback) {
          KOC.MysqlHelper.TranOpen(Config.Mysql.DB.User, function (retValue) {
            if (retValue.hasError) {
              callback(retValue);
              return;
            }
            _Conn = retValue.returnObject;
            callback();
          });
        },
        //减少用户星星及增加用户经验
        function (callback) {
          DAL_Factory.User.User_Info.Update_PomeloPresent(_Conn, {
            Num: parm.Num,
            EXP: parm.EXP,
            User_ID: parm.User_ID
          }, function (retValue) {
            if (retValue.hasError) {
              callback(retValue);
              return;
            }
            if (retValue.returnObject !== 1) {
              retValue.hasError = true;
              retValue.message = "减少用户星星数量出错，影响行(" + retValue.returnObject + ")";
              callback(retValue);
              return;
            }
            callback();
          });
        },
        //增加艺人星星级经验
        function (callback) {
          DAL_Factory.User.User_Anchor.Update_Pomelo(_Conn, {
            Num: parm.Num,
            EXP: parm.EXP_Anchor,
            User_ID: parm.User_ID_Anchor
          }, function (retValue) {
            if (retValue.hasError) {
              callback(retValue);
              return;
            }
            if (retValue.returnObject !== 1) {
              retValue.hasError = true;
              retValue.message = "增加艺人星星及经验出错，影响行(" + retValue.returnObject + ")";
              callback(retValue);
              return;
            }
            callback();
          });
        },
        //更新直播单据
        function (callback) {
          if (!parm.Live_Order_No) {
            callback();
            return;
          }
          DAL_Factory.User.Order_Live.Update_Pomelo(_Conn, {
            Order_No: parm.Live_Order_No,
            User_ID: parm.User_ID_Anchor,
            Num: parm.Num
          }, function (retValue) {
            if (retValue.hasError) {
              callback(retValue);
              return;
            }
            if (retValue.returnObject !== 1) {
              retValue.hasError = true;
              retValue.message = "更新直播单数据出错，影响行(" + retValue.returnObject + ")";
              callback(retValue);
              return;
            }
            callback();
          });
        },
        //提交事务
        function (callback) {
          KOC.MysqlHelper.TranCommit(_Conn, function (retValue) {
            _Conn = null;
            if (retValue.hasError) {
              callback(retValue);
              return;
            }
            callback();
          });
        },
        //更新艺人热度
        function (callback) {
          DAL_Factory.Business.User_AnchorHot({
            Type: "Pomelo",
            Num: parm.Num,
            Value: CommonUtils.Anchor.Hot.Pomelo * (KOC.Lodash.includes(CommonUtils.Anchor.Hot.PomeloSpecial, parm.User_ID) ? CommonUtils.Anchor.Hot.PomeloSpecialMultiple : 1),
            User_ID: parm.User_ID_Anchor
          }, function () {
            callback();
          });
        },
        //任务提交
        function (callback) {
          DAL_Factory.Business.User_Task({
            User_ID: parm.User_ID,
            User_NickName: parm.User_NickName,
            User_RealName: parm.User_RealName,
            Task_ID: 1002,
            Task_Progress: parm.Num,
            Create_IP: parm.Create_IP
          }, function () {
            callback();
          });
        }
      ], function (retValue) {
        if (retValue) {
          console.log("赠送星星失败:", retValue, parm);
          KOC.MysqlHelper.TranRollback(_Conn, function () {
            callback(retValue);
          });
          return;
        }
        callback(KOC.ReturnValue.New({
          returnObject: {
            User_ID: parm.User_ID,
            User_ID_Anchor: parm.User_ID_Anchor,
            Num: parm.Num,
            EXP: parm.EXP,
            EXP_Anchor: parm.EXP_Anchor,
            User_Pomelo: parm.User_Pomelo,
            User_EXP: parm.User_EXP,
            Anchor_Fans: parm.Anchor_Fans,
            Anchor_Attention: parm.Anchor_Attention,
            Anchor_Pomelo: parm.Anchor_Pomelo,
            Anchor_EXP: parm.Anchor_EXP,
            Live_Order_No: parm.Live_Order_No
          }
        }));
      });
    },
    //endregion
    //region User_Task:用户任务提交
    User_Task: function (parm, callback) {
      parm = KOC.Lodash.extend({
        User_ID: null,
        User_NickName: null,
        User_RealName: null,
        Task_ID: null,
        Task_Progress: null,
        Create_IP: null
      }, parm);
      parm.Task_Progress = KOC.StringUtils.ToInt(parm.Task_Progress);
      if (parm.Task_Progress <= 0) {
        callback(KOC.ReturnValue.New({
          hasError: true,
          message: "任务完成度错误:Task_Progress"
        }));
        return;
      }
      var _UserTaskStatus = -1; //-1:无 0:已领取 1:执行中 2:已完成 3:已失效(过期)
      KOC.Async.series([
        //读取任务信息
        function (callback) {
          parm.Task_Info = CommonUtils.Task.fnInfo(parm.Task_ID);
          if (!parm.Task_Info) {
            callback(KOC.ReturnValue.New({
              hasError: true,
              message: "没有相关的任务信息"
            }));
            return;
          }
          if (parm.Task_Info.Status != 0) {
            callback(KOC.ReturnValue.New({
              hasError: true,
              message: "此任务已被锁定"
            }));
            return;
          }
          parm.Task_ID = parm.Task_Info.id;
          parm.Task_Mode = parm.Task_Info.Mode;
          callback();
        },
        //读取用户任务信息
        function (callback) {
          DAL_Factory.User.User_Task.Info(parm.User_ID, parm.Task_ID, parm.Task_Mode, null, function (retValue) {
            if (retValue.hasError) {
              callback(retValue);
              return;
            }
            if (!retValue.returnObject) {
              callback();
              return;
            }
            _UserTaskStatus = retValue.returnObject.Status;
            callback();
          });
        },
        //读取用户信息
        function (callback) {
          if (_UserTaskStatus !== -1 || (parm.User_NickName != undefined && parm.User_RealName != undefined)) {
            callback();
            return;
          }
          DAL_Factory.User.User_Info.Info(parm.User_ID, function (retValue) {
            if (retValue.hasError) {
              callback(retValue);
              return;
            }
            if (!retValue.returnObject) {
              retValue.hasError = true;
              retValue.message = "用户不存在";
              callback(retValue);
              return;
            }
            if (retValue.returnObject.Status !== 0) {
              retValue.hasError = true;
              retValue.message = "用户已被锁定";
              callback(retValue);
              return;
            }
            parm.User_NickName = retValue.returnObject.NickName;
            parm.User_RealName = retValue.returnObject.RealName;
            callback();
          });
        },
        //新建用户任务信息
        function (callback) {
          if (_UserTaskStatus !== -1) {
            callback();
            return;
          }
          DAL_Factory.User.User_Task.Insert({
            User_ID: parm.User_ID,
            User_NickName: parm.User_NickName,
            User_RealName: parm.User_RealName,
            Task_ID: parm.Task_ID,
            Task_Name: parm.Task_Info.Name,
            Task_Mode: parm.Task_Mode,
            Task_Objective: parm.Task_Info.Objective,
            Task_Reward: JSON.stringify(parm.Task_Info.Reward),
            Create_IP: parm.Create_IP
          }, function (retValue) {
            if (retValue.hasError) {
              callback(retValue);
              return;
            }
            _UserTaskStatus = 1;
            callback();
          });
        },
        //提交用户任务(修改)
        function (callback) {
          if (_UserTaskStatus !== 1) {
            callback();
            return;
          }
          DAL_Factory.User.User_Task.Update({
            User_ID: parm.User_ID,
            Task_ID: parm.Task_ID,
            Task_Mode: parm.Task_Mode,
            Task_Progress: parm.Task_Progress
          }, function (retValue) {
            if (retValue.hasError) {
              callback(retValue);
              return;
            }
            if (retValue.returnObject !== 1) {
              retValue.hasError = true;
              retValue.message = "提交任务信息出错(影响" + retValue.returnObject + "行)";
              callback(retValue);
              return;
            }
            callback();
          });
        }
      ], function (retValue) {
        if (retValue) {
          console.log("提交任务失败:", retValue, parm);
          callback(retValue);
          return;
        }
        callback(KOC.ReturnValue.New());
      });
    },
    //endregion
    //region User_TaskReceive:用户任务奖励领取
    User_TaskReceive: function (parm, callback) {
      parm = KOC.Lodash.extend({
        User_ID: null,
        Task_ID: null,
        Task_Mode: null,
        Task_Date: null,
        Create_IP: null
      }, parm);
      var _Conn = null;
      KOC.Async.series([
        //读取用户任务信息
        function (callback) {
          DAL_Factory.User.User_Task.Info(parm.User_ID, parm.Task_ID, parm.Task_Mode, parm.Task_Date, function (retValue) {
            if (retValue.hasError) {
              callback(retValue);
              return;
            }
            if (!retValue.returnObject) {
              retValue.hasError = true;
              retValue.message = "没有找到可领取的任务信息";
              callback(retValue);
              return;
            }
            if (retValue.returnObject.Status == 0) {
              retValue.hasError = true;
              retValue.message = "此任务已经领取";
              callback(retValue);
              return;
            }
            if (retValue.returnObject.Status == 1) {
              retValue.hasError = true;
              retValue.message = "此任务正在执行中";
              callback(retValue);
              return;
            }
            if (retValue.returnObject.Status == 3) {
              retValue.hasError = true;
              retValue.message = "此任务已失效";
              callback(retValue);
              return;
            }
            try {
              parm.Task_Reward = JSON.parse(retValue.returnObject.Task_Reward);
            } catch (ex) {
            }
            if (!parm.Task_Reward) {
              retValue.hasError = true;
              retValue.message = "任务奖励配置出错,请和管理员联系(1)";
              callback(retValue);
              return;
            }
            parm.User_ID = retValue.returnObject.User_ID;
            parm.Task_ID = retValue.returnObject.Task_ID;
            parm.Task_Date = retValue.returnObject.Task_Date;
            parm.Task_Mode = retValue.returnObject.Task_Mode;
            parm.Task_Name = retValue.returnObject.Task_Name;
            callback();
          });
        },
        //开启事物
        function (callback) {
          KOC.MysqlHelper.TranOpen(Config.Mysql.DB.User, function (retValue) {
            if (retValue.hasError) {
              callback(retValue);
              return;
            }
            _Conn = retValue.returnObject;
            callback();
          });
        },
        //修改任务状态
        function (callback) {
          DAL_Factory.User.User_Task.Update_Receive(_Conn, {
            User_ID: parm.User_ID,
            Task_ID: parm.Task_ID,
            Task_Mode: parm.Task_Mode,
            Task_Date: parm.Task_Date
          }, function (retValue) {
            if (retValue.hasError) {
              callback(retValue);
              return;
            }
            if (retValue.returnObject !== 1) {
              retValue.hasError = true;
              retValue.message = "修改任务领取状态出错(影响" + retValue.returnObject + "行)";
              callback(retValue);
              return;
            }
            callback();
          });
        },
        //任务奖励发放
        function (callback) {
          KOC.Async.each(parm.Task_Reward, function (ThisValue, callback) {
            switch (ThisValue.Type) {
              case "COIN": //金币
                DAL_Factory.Business.User_BankTransction(_Conn, {
                  User_ID: parm.User_ID,
                  Related_User_ID: -1,
                  Related_User_NickName: "",
                  Related_User_RealName: "",
                  Related_Family_ID: -1,
                  Related_Family_Name: "",
                  Trade_Currency: 1,
                  Trade_Type: 104,
                  Trade_Flag: 1,
                  Trade_Amt: ThisValue.Value,
                  Trade_Order_No: "",
                  Remark: "任务奖励:" + parm.Task_Name + " (ID:" + parm.Task_ID + ", Mode:" + parm.Task_Mode + ", Date:" + parm.Task_Date + ")",
                  Create_IP: parm.Create_IP
                }, function (retValue) {
                  callback(retValue.hasError ? retValue : null);
                });
                return;
              case "EXP": //经验
                DAL_Factory.User.User_Info.Update_EXP(_Conn, {
                  EXP: ThisValue.Value,
                  User_ID: parm.User_ID
                }, function (retValue) {
                  if (retValue.hasError) {
                    callback(retValue);
                    return;
                  }
                  if (retValue.returnObject !== 1) {
                    retValue.hasError = true;
                    retValue.message = "发放经验奖励出错(影响" + retValue.returnObject + "行)";
                    callback(retValue);
                    return;
                  }
                  callback();
                });
                return;
              case "POMELO": //星星
                DAL_Factory.User.User_Info.Update_Pomelo(_Conn, parm.User_ID, ThisValue.Value, function (retValue) {
                  if (retValue.hasError) {
                    callback(retValue);
                    return;
                  }
                  if (retValue.returnObject !== 1) {
                    retValue.hasError = true;
                    retValue.message = "发放星星奖励出错(影响" + retValue.returnObject + "行)";
                    callback(retValue);
                    return;
                  }
                  callback();
                });
                return;
              case "GIFT": //礼物
                DAL_Factory.Business.User_PackageTransction(_Conn, {
                  User_ID: parm.User_ID,
                  Item_Type: "Gift",
                  Item_ID: ThisValue.ID,
                  Trade_Type: 102,
                  Trade_Flag: 1,
                  Trade_Num: ThisValue.Value,
                  Trade_Order_No: "",
                  Remark: "任务奖励:" + parm.Task_Name + " (ID:" + parm.Task_ID + ", Mode:" + parm.Task_Mode + ", Date:" + parm.Task_Date + ")",
                  Create_IP: parm.Create_IP
                }, function (retValue) {
                  callback(retValue.hasError ? retValue : null);
                });
                return;
              case "HORN": //喇叭
                DAL_Factory.Business.User_PackageTransction(_Conn, {
                  User_ID: parm.User_ID,
                  Item_Type: "Horn",
                  Item_ID: ThisValue.Mode,
                  Trade_Type: 102,
                  Trade_Flag: 1,
                  Trade_Num: ThisValue.Value,
                  Trade_Order_No: "",
                  Remark: "任务奖励:" + parm.Task_Name + " (ID:" + parm.Task_ID + ", Mode:" + parm.Task_Mode + ", Date:" + parm.Task_Date + ")",
                  Create_IP: parm.Create_IP
                }, function (retValue) {
                  callback(retValue.hasError ? retValue : null);
                });
                return;
              case "VIP": //VIP
                DAL_Factory.User.User_Info.Update_VIP(_Conn, {
                  VIP_Mode: ThisValue.Mode,
                  VIP_Value: ThisValue.Value,
                  User_ID: parm.User_ID
                }, function (retValue) {
                  if (retValue.hasError) {
                    callback(retValue);
                    return;
                  }
                  if (retValue.returnObject !== 1) {
                    retValue.hasError = true;
                    retValue.message = "发放VIP奖励出错(影响" + retValue.returnObject + "行)";
                    callback(retValue);
                    return;
                  }
                  callback();
                });
                return;
              case "MOUNTS": //座骑
                var _MountsInfo = CommonUtils.Commodity.Mounts.fnInfo(ThisValue.ID); //读取座骑信息
                DAL_Factory.User.User_Mounts.Insert(_Conn, {
                  User_ID: parm.User_ID,
                  Mounts_ID: ThisValue.ID,
                  Mounts_Mode: ThisValue.Mode,
                  Mounts_Value: ThisValue.Value,
                  Mounts_Name: _MountsInfo.Name,
                  Create_IP: parm.Create_IP
                }, function (retValue) {
                  callback(retValue.hasError ? retValue : null);
                });
                return;
              case "EMBLEM":
                var _EmblemInfo = CommonUtils.Commodity.Emblem.fnInfo(ThisValue.ID); //读取徽章信息
                DAL_Factory.User.User_Emblem.Insert(_Conn, {
                  User_ID: parm.User_ID,
                  Item_ID: ThisValue.ID,
                  Item_Mode: ThisValue.Mode,
                  Item_Value: ThisValue.Value,
                  Item_Name: _EmblemInfo.Name,
                  Item_Type: _EmblemInfo.Type,
                  Create_IP: parm.Create_IP
                }, function (retValue) {
                  callback(retValue.hasError ? retValue : null);
                });
                return;
              default:
                callback(KOC.ReturnValue.New({
                  hasError: true,
                  message: "任务奖励配置出错,请与管理员联系(2)"
                }));
                return;
            }
          }, function (retValue) {
            console.log(333, retValue);
            if (retValue) {
              callback(retValue);
              return;
            }
            callback();
          });
        },
        //提交事务
        function (callback) {
          KOC.MysqlHelper.TranCommit(_Conn, function (retValue) {
            _Conn = null;
            if (retValue.hasError) {
              callback(retValue);
              return;
            }
            callback();
          });
        }
      ], function (retValue) {
        if (retValue) {
          console.log("任务奖励领取失败:", retValue, parm);
          KOC.MysqlHelper.TranRollback(_Conn, function () {
            callback(retValue);
          });
          return;
        }
        callback(KOC.ReturnValue.New());
      });
    },
    //endregion
    //region User_Attention:用户关注
    User_Attention: function (parm, callback) {
      parm = KOC.Lodash.extend({
        User_ID: null,
        User_ID_Attention: null,
        Cancel: null//取消关注为true,关注不传
      }, parm);
      var _Conn = null;
      KOC.Async.series([
        //开启事物
        function (callback) {
          KOC.MysqlHelper.TranOpen(Config.Mysql.DB.User, function (retValue) {
            if (retValue.hasError) {
              callback(retValue);
              return;
            }
            _Conn = retValue.returnObject;
            callback();
          });
        },
        //写入用户关注
        function (callback) {
          if (parm.Cancel) {
            callback();
            return;
          }
          DAL_Factory.User.User_Attention.Insert(_Conn, {
            User_ID: parm.User_ID,
            User_ID_Attention: parm.User_ID_Attention
          }, function (retValue) {
            if (retValue.hasError) {
              retValue.errorCode = 1;
              retValue.message = "您已关注过该用户了。";
              callback(retValue);
              return;
            }
            callback();
          });
        },
        //取消用户关注
        function (callback) {
          if (!parm.Cancel) {
            callback();
            return;
          }
          DAL_Factory.User.User_Attention.Delete(_Conn, {
            User_ID: parm.User_ID,
            User_ID_Attention: parm.User_ID_Attention
          }, function (retValue) {
            if (retValue.hasError) {
              callback(retValue);
              return;
            }
            callback();
          });
        },
        //修改关注数量
        function (callback) {
          DAL_Factory.User.User_Info.Update_Attention(_Conn, {
            Num: parm.Cancel ? -1 : 1,
            User_ID: parm.User_ID
          }, function (retValue) {
            if (retValue.hasError) {
              callback(retValue);
              return;
            }
            if (retValue.returnObject !== 1) {
              retValue.hasError = true;
              retValue.message = "修改用户关注数量出错，影响行(" + retValue.returnObject + ")";
              callback(retValue);
              return;
            }
            callback();
          });
        },
        //修改粉丝数量
        function (callback) {
          DAL_Factory.User.User_Info.Update_Fans(_Conn, {
            Num: parm.Cancel ? -1 : 1,
            User_ID: parm.User_ID_Attention
          }, function (retValue) {
            if (retValue.hasError) {
              callback(retValue);
              return;
            }
            if (retValue.returnObject !== 1) {
              retValue.hasError = true;
              retValue.message = "修改用户粉丝数量出错，影响行(" + retValue.returnObject + ")";
              callback(retValue);
              return;
            }
            callback();
          });
        }
      ], function (retValue) {
        if (retValue) {
          // console.log("关注用户失败:", retValue, parm);
          KOC.MysqlHelper.TranRollback(_Conn, function () {
            callback(retValue);
          });
          return;
        }
        KOC.MysqlHelper.TranCommit(_Conn, function (retValue) {
          if (retValue.hasError) {
            callback(retValue);
            return;
          }
          retValue = KOC.ReturnValue.New();
          retValue.returnObject = parm;
          callback(retValue);
        });
      });
    },
    //endregion
    //region User_Contribution:用户贡献
    User_Contribution: function (Conn, parm, callback) {
      if (!Conn) {
        callback(KOC.ReturnValue.New({
          hasError: false,
          message: "Connection is null"
        }));
        return;
      }
      parm = KOC.Lodash.extend({
        User_ID: null,
        User_ID_Contribution: null,
        Coin: null,
        Live: null
      }, parm);
      var _Insert = false;
      KOC.Async.series([
        //修改贡献数据
        function (callback) {
          DAL_Factory.User.User_Contribution.Update(Conn, parm, function (retValue) {
            if (retValue.hasError) {
              callback(retValue);
              return;
            }
            if (retValue.returnObject !== 1) {
              _Insert = true;
            }
            callback();
          });
        },
        //写入贡献数据
        function (callback) {
          if (!_Insert) {
            callback();
            return;
          }
          DAL_Factory.User.User_Contribution.Insert(Conn, parm, function (retValue) {
            if (retValue.hasError) {
              callback(retValue);
              return;
            }
            callback();
          });
        }
      ], function (retValue) {
        if (retValue) {
          callback(retValue);
          return;
        }
        callback(KOC.ReturnValue.New());
      });
    },
    //endregion
    //region User_PayOrder:用户充值，下订单
    User_PayOrder: function (parm, callback) {
      parm = KOC.Lodash.extend({
        User_ID: null,
        Pay_Type: null,
        Pay_Style: null,
        Pay_From: null,
        Pay_Money: null,
        Create_IP: null
      }, parm);
      //充值金额处理
      if (parm.Pay_Type == 12 || parm.Pay_Type == 13 || parm.Pay_Type == 14 || parm.Pay_Type == 15) {
        parm.Pay_Coin = parm.Pay_Money * 0.95 * 1000;
        parm.Pay_Poundage = parm.Pay_Money * 0.05 * 1000;
      } else {
        parm.Pay_Coin = parm.Pay_Money * 10;
        parm.Pay_Poundage = 0;
      }
      //苹果支付特殊处理
      if (parm.Pay_From == 2) {
        switch (parm.Pay_Money) {
          case 1 :
            parm.Pay_Poundage = parm.Pay_Coin - 700;
            parm.Pay_Coin = 700;
            break;
          case 8 :
            parm.Pay_Poundage = parm.Pay_Coin - 5400;
            parm.Pay_Coin = 5400;
            break;
          case 18 :
            parm.Pay_Poundage = parm.Pay_Coin - 12300;
            parm.Pay_Coin = 12300;
            break;
          case 68 :
            parm.Pay_Poundage = parm.Pay_Coin - 46600;
            parm.Pay_Coin = 46600;
            break;
          case 98 :
            parm.Pay_Poundage = parm.Pay_Coin - 67200;
            parm.Pay_Coin = 67200;
            break;
          case 198 :
            parm.Pay_Poundage = parm.Pay_Coin - 135800;
            parm.Pay_Coin = 135800;
            break;
          case 588 :
            parm.Pay_Poundage = parm.Pay_Coin - 403400;
            parm.Pay_Coin = 403400;
            break;
          case 998 :
            parm.Pay_Poundage = parm.Pay_Coin - 684700;
            parm.Pay_Coin = 684700;
            break;
          case 5898 :
            parm.Pay_Poundage = parm.Pay_Coin - 4046400;
            parm.Pay_Coin = 4046400;
            break;
          default :
            callback(KOC.ReturnValue.New({
              hasError: true,
              message: "订单金额出错"
            }));
            return;
        }
      }
      KOC.Async.series([
        //读取用户个人信息
        function (callback) {
          DAL_Factory.User.User_Info.Info(parm.User_ID, function (retValue) {
            if (retValue.hasError) {
              callback(retValue);
              return;
            }
            if (!retValue.returnObject) {
              retValue.hasError = true;
              retValue.message = "用户不存在";
              callback(retValue);
              return;
            }
            parm.User_NickName = retValue.returnObject.NickName;
            parm.Channel_ID = retValue.returnObject.Channel_ID;
            callback();
          });
        },
        //生成单据号
        function (callback) {
          DAL_Factory.Common.Order_No_Manage.Info(CommonUtils.OrderNo.Pay.ID, function (retValue) {
            if (retValue.hasError) {
              callback(retValue);
              return;
            }
            if (!retValue.returnObject || !retValue.returnObject[0].Order_No) {
              retValue.hasError = true;
              retValue.message = "无此单据类型";
              callback(retValue);
              return;
            }
            parm.Order_No = retValue.returnObject[0].Order_No;
            callback();
          });
        },
        //插入充值交易表单
        function (callback) {
          DAL_Factory.User.Order_Pay.Insert({
            Order_No: parm.Order_No,
            User_ID: parm.User_ID,
            User_NickName: parm.User_NickName,
            Channel_ID: parm.Channel_ID,
            Pay_Type: parm.Pay_Type,
            Pay_Style: parm.Pay_Style,
            Pay_From: parm.Pay_From,
            Pay_Money: parm.Pay_Money,
            Pay_Coin: parm.Pay_Coin,
            Pay_Poundage: parm.Pay_Poundage,
            Create_IP: parm.Create_IP
          }, function (retValue) {
            if (retValue.hasError) {
              callback(retValue);
              return;
            }
            callback();
          });
        }
      ], function (retValue) {
        if (retValue) {
          console.log("用户下订单失败:", retValue, parm);
          callback(retValue);
          return;
        }
        callback(KOC.ReturnValue.New({
          returnObject: parm
        }));
      });
    },
    //endregion
    //region User_PayMoney:用户充值，付款
    User_PayMoney: function (parm, callback) {
      parm = KOC.Lodash.extend({
        Pay_Money: null,//充值金额
        Order_No: null, //订单号
        Pay_TransNumber: null,//支付返回的交易号
        Create_IP: null
      }, parm);
      if (!parm.Create_IP || parm.Create_IP == undefined) {
        parm.Create_IP = "";
      }
      parm.Pay_Money = parseFloat(parm.Pay_Money);
      if (!parm.Pay_Money || parm.Pay_Money <= 0) {
        callback(KOC.ReturnValue.New({
          hasError: true,
          message: "充值的金额不大于零"
        }));
        return;
      }
      var _Conn = null;
      KOC.Async.series([
        //查询订单
        function (callback) {
          DAL_Factory.User.Order_Pay.Info(parm.Order_No, function (retValue) {
            if (retValue.hasError) {
              callback(retValue);
              return;
            }
            if (!retValue.returnObject) {
              retValue.hasError = true;
              retValue.message = "订单号错误，订单不存在";
              callback(retValue);
              return;
            }
            if (retValue.returnObject.Status == 0) {
              retValue.hasError = true;
              retValue.message = "订单已支付";
              callback(retValue);
              return;
            }
            //判断充值金额和实际金额是否相符合
            if (parm.Pay_Money.toFixed(2) != parm.Pay_Money || retValue.returnObject.Pay_Money != parm.Pay_Money.toFixed(2)) {
              retValue.hasError = true;
              retValue.message = "充值金额与订单金额不符";
              callback(retValue);
              return;
            }
            parm.Trade_Amt = retValue.returnObject.Pay_Coin;//记录用户实际获得的金币数
            parm.User_ID = retValue.returnObject.User_ID;//获取充值用户ID
            parm.Pay_Money = retValue.returnObject.Pay_Money;//充值钱数
            callback();
          });
        },
        //读取用户个人信息
        function (callback) {
          DAL_Factory.User.User_Info.Info(parm.User_ID, function (retValue) {
            if (retValue.hasError) {
              callback(retValue);
              return;
            }
            if (!retValue.returnObject) {
              retValue.hasError = true;
              retValue.message = "用户不存在";
              callback(retValue);
              return;
            }
            parm.Charge_First = retValue.returnObject.Charge_First;//首冲标记
            parm.Charge_First_Award = retValue.returnObject.Charge_First;//首冲奖励
            parm.EXP = retValue.returnObject.EXP;
            parm.User_NickName = retValue.returnObject.NickName;
            parm.User_RealName = retValue.returnObject.RealName;
            callback();
          });
        },
        //开启事物
        function (callback) {
          KOC.MysqlHelper.TranOpen(Config.Mysql.DB.User, function (retValue) {
            if (retValue.hasError) {
              callback(retValue);
              return;
            }
            _Conn = retValue.returnObject;
            callback();
          });
        },
        //更新充值交易单
        function (callback) {
          DAL_Factory.User.Order_Pay.Update(_Conn, {
            Order_No: parm.Order_No,
            User_ID: parm.User_ID,
            Pay_TransNumber: parm.Pay_TransNumber
          }, function (retValue) {
            if (retValue.hasError) {
              callback(retValue);
              return;
            }
            if (retValue.returnObject !== 1) {
              retValue.hasError = true;
              retValue.message = "更新充值交易单出错，影响行(" + retValue.returnObject + ")";
              callback(retValue);
              return;
            }
            callback();
          });
        },
        //更新用户的金币数（充值获得的金币）
        function (callback) {
          DAL_Factory.Business.User_BankTransction(_Conn, {
            User_ID: parm.User_ID,
            Related_User_ID: null,
            Related_User_NickName: null,
            Related_User_RealName: null,
            Related_Family_ID: null,
            Related_Family_Name: null,
            Trade_Currency: 1,
            Trade_Type: 101,//
            Trade_Flag: 1,//增加用户金币
            Trade_Amt: parm.Trade_Amt,
            Trade_Order_No: parm.Order_No,
            Remark: "",
            Create_IP: parm.Create_IP
          }, function (retValue) {
            if (retValue.hasError) {
              callback(retValue);
              return;
            }
            callback();
          });
        },
        //首冲奖励领取
        function (callback) {
          if (parm.Charge_First_Award) {
            callback();
            return;
          }

          //增加经验值
          function AddExp(EXP) {
            if (parm.EXP >= EXP) {
              //增加经验
              parm.EXP_ADD = EXP;
            } else {
              //直升等级
              parm.EXP_ADD = EXP - parm.EXP;
            }
          }

          //初始化
          parm.EXP_ADD = 0;//增加经验
          parm.VIP_Day = 0;//增加VIP天数
          parm.Mounts_Day = 0;//增加坐骑天数
          parm.Mounts_ID = 0;//坐骑ID
          parm.Room_Count = 0;//飞屏卡数量
          parm.Server_Count = 0;//喇叭数量
          parm.VIP_Name = "";//vip 名称
          parm.VIP_Mode = "DAY";
          parm.Mounts_Name = "";//坐骑名称
          parm.Mounts_Mode = "DAY";
          if (parm.Pay_Money >= 10 && parm.Pay_Money < 50) {
            //经验增加
            AddExp(150000);
            //飞屏卡赠送
            parm.Room_Count = 5;
            //喇叭卡赠送
            parm.Server_Count = 5;
            //座驾赠送
            parm.Mounts_Day = 5;
            parm.Mounts_ID = 59;
            parm.Mounts_Name = "跑车";
            //VIP赠送
            parm.VIP_Day = 5;
            parm.VIP_Name = "5天";
          } else if (parm.Pay_Money >= 50 && parm.Pay_Money < 100) {
            //经验增加
            AddExp(200000);
            //飞屏卡赠送
            parm.Room_Count = 10;
            //喇叭卡赠送
            parm.Server_Count = 10;
            //座驾赠送
            parm.Mounts_Day = 10;
            parm.Mounts_ID = 59;
            parm.Mounts_Name = "跑车";
            //VIP赠送
            parm.VIP_Day = 10;
            parm.VIP_Name = "10天";
          } else if (parm.Pay_Money >= 100 && parm.Pay_Money < 500) {
            //经验增加
            AddExp(250000);
            //飞屏卡赠送
            parm.Room_Count = 15;
            //喇叭卡赠送
            parm.Server_Count = 15;
            //座驾赠送
            parm.Mounts_Day = 15;
            parm.Mounts_ID = 60;
            parm.Mounts_Name = "宝马";
            //VIP赠送
            parm.VIP_Day = 15;
            parm.VIP_Name = "15天";
          } else if (parm.Pay_Money >= 500 && parm.Pay_Money < 1000) {
            //经验增加
            AddExp(300000);
            //飞屏卡赠送
            parm.Room_Count = 20;
            //喇叭卡赠送
            parm.Server_Count = 20;
            //座驾赠送
            parm.Mounts_Day = 20;
            parm.Mounts_ID = 58;
            parm.Mounts_Name = "玛莎拉蒂";
            //VIP赠送
            parm.VIP_Day = 20;
            parm.VIP_Name = "20天";
          } else if (parm.Pay_Money >= 1000 && parm.Pay_Money < 3000) {
            //经验增加
            AddExp(350000);
            //飞屏卡赠送
            parm.Room_Count = 30;
            //喇叭卡赠送
            parm.Server_Count = 30;
            //座驾赠送
            parm.Mounts_Day = 30;
            parm.Mounts_ID = 58;
            parm.Mounts_Name = "玛莎拉蒂";
            //VIP赠送
            parm.VIP_Day = 30;
            parm.VIP_Name = "30天";
          } else if (parm.Pay_Money >= 3000 && parm.Pay_Money < 5000) {
            //经验增加
            AddExp(400000);
            //飞屏卡赠送
            parm.Room_Count = 40;
            //喇叭卡赠送
            parm.Server_Count = 40;
            //座驾赠送
            parm.Mounts_Day = 40;
            parm.Mounts_ID = 61;
            parm.Mounts_Name = "嘲天吼";
            //VIP赠送
            parm.VIP_Day = 40;
            parm.VIP_Name = "40天";
          } else if (parm.Pay_Money >= 5000) {
            //经验增加
            AddExp(1000000);
            //飞屏卡赠送
            parm.Room_Count = 60;
            //喇叭卡赠送
            parm.Server_Count = 60;
            //座驾赠送
            parm.Mounts_Day = 60;
            parm.Mounts_ID = 61;
            parm.Mounts_Name = "嘲天吼";
            //VIP赠送
            parm.VIP_Day = 60;
            parm.VIP_Name = "60天";
          } else {
            console.log("首冲都不到10块，没奖励");
          }
          callback();
        },
        //修改用户经验值
        function (callback) {
          if (parm.Charge_First || (!parm.EXP_ADD || parm.EXP_ADD <= 0)) {
            callback();
            return;
          }
          DAL_Factory.User.User_Info.Update_EXP(_Conn, {
            EXP: parm.EXP_ADD,
            User_ID: parm.User_ID
          }, function (retValue) {
            if (retValue.hasError) {
              callback(retValue);
              return;
            }
            callback();
          });
        },
        //更新用户VIP信息
        function (callback) {
          if (parm.Charge_First || (!parm.VIP_Day || parm.VIP_Day <= 0)) {
            callback();
            return;
          }
          DAL_Factory.User.User_Info.Update_VIP(_Conn, {
            VIP_Mode: parm.VIP_Mode,
            VIP_Value: parm.VIP_Day,
            User_ID: parm.User_ID
          }, function (retValue) {
            if (retValue.hasError) {
              callback(retValue);
              return;
            }
            if (retValue.returnObject !== 1) {
              retValue.hasError = true;
              retValue.message = "更新用户VIP信息出错，影响行(" + retValue.returnObject + ")";
              callback(retValue);
              return;
            }
            callback();
          });
        },
        //写入座骑信息
        function (callback) {
          if (parm.Charge_First || (!parm.Mounts_Day || parm.Mounts_Day <= 0 || !parm.Mounts_ID || parm.Mounts_ID <= 0)) {
            callback();
            return;
          }
          DAL_Factory.User.User_Mounts.Insert(_Conn, {
            User_ID: parm.User_ID,
            Mounts_ID: parm.Mounts_ID,
            Mounts_Mode: parm.Mounts_Mode,
            Mounts_Value: parm.Mounts_Day,
            Mounts_Name: parm.Mounts_Name,
            Create_IP: parm.Create_IP
          }, function (retValue) {
            if (retValue.hasError) {
              callback(retValue);
              return;
            }
            callback();
          });
        },
        //放入包裹 喇叭
        function (callback) {
          if (parm.Charge_First || (!parm.Server_Count || parm.Server_Count <= 0)) {
            callback();
            return;
          }
          DAL_Factory.Business.User_PackageTransction(_Conn, {
            User_ID: parm.User_ID,
            Item_Type: "Horn",
            Item_ID: "SERVER",
            Trade_Type: 101,
            Trade_Flag: 1,
            Trade_Num: parm.Server_Count,
            Trade_Order_No: parm.Order_No,//充值订单号
            Remark: "首冲-送喇叭",
            Create_IP: parm.Create_IP
          }, function (retValue) {
            if (retValue.hasError) {
              callback(retValue);
              return;
            }
            callback();
          });
        },
        //放入包裹 飞屏卡
        function (callback) {
          if (parm.Charge_First || (!parm.Room_Count || parm.Room_Count <= 0)) {
            callback();
            return;
          }
          DAL_Factory.Business.User_PackageTransction(_Conn, {
            User_ID: parm.User_ID,
            Item_Type: "Horn",
            Item_ID: "ROOM",
            Trade_Type: 101,
            Trade_Flag: 1,
            Trade_Num: parm.Room_Count,
            Trade_Order_No: parm.Order_No,//充值订单号
            Remark: "首冲-送飞屏卡",
            Create_IP: parm.Create_IP
          }, function (retValue) {
            if (retValue.hasError) {
              callback(retValue);
              return;
            }
            callback();
          });
        },
        //更新首冲标记
        function (callback) {
          //更改用户的首冲标记,首冲时间,首冲奖励标记和最新一次充值的时间
          DAL_Factory.User.User_Info.Update_Charge(_Conn, parm.User_ID, function (retValue) {
            if (retValue.hasError) {
              callback(retValue);
              return;
            }
            if (retValue.returnObject !== 1) {
              retValue.hasError = true;
              retValue.message = "更新更新首冲标记出错，影响行(" + retValue.returnObject + ")";
              callback(retValue);
              return;
            }
            callback();
          });
        },
        //提交事务
        function (callback) {
          KOC.MysqlHelper.TranCommit(_Conn, function (retValue) {
            _Conn = null;
            if (retValue.hasError) {
              callback(retValue);
              return;
            }
            callback();
          });
        },
        //任务提交
        function (callback) {
          DAL_Factory.Business.User_Task({
            User_ID: parm.User_ID,
            User_NickName: parm.User_NickName,
            User_RealName: parm.User_RealName,
            Task_ID: 1003,
            Task_Progress: 1,
            Create_IP: parm.Create_IP
          }, function () {
            callback();
          });
        }
      ], function (retValue) {
        if (retValue) {
          console.log("用户充值付款失败:", retValue, parm);
          KOC.MysqlHelper.TranRollback(_Conn, function () {
            callback(retValue);
          });
          return;
        }
        //返回
        retValue = KOC.ReturnValue.New();
        retValue.returnObject = parm;
        callback(retValue);
      });
    },
    //endregion
    //region User_CheckPhone:验证用户绑定手机
    User_CheckPhone: function (parm, callback) {
      parm = KOC.Lodash.extend({
        Phone: null,
        PhoneCode: null//手机验证码
      }, parm);
      KOC.Async.series([
        //读取用户个人信息
        function (callback) {
          DAL_Factory.User.User_Info.Info_Phone(parm.Phone, function (retValue) {
            if (retValue.hasError) {
              callback(retValue);
              return;
            }
            if (!retValue.returnObject) {
              retValue.hasError = true;
              retValue.message = "该手机未绑定用户";
              callback(retValue);
              return;
            }
            callback();
          });
        },
        //手机验证码验证
        function (callback) {
          DAL_Factory.RedisCommon.PhoneAuthCode.Check(parm.Phone, parm.PhoneCode, function (retValue) {
            if (retValue.hasError) {
              callback(retValue);
              return;
            }
            callback();
          });
        }
      ], function (retValue) {
        if (retValue) {
          callback(retValue);
          return;
        }
        callback(KOC.ReturnValue.New());
      });
    },
    //endregion
    //region User_VerifyIDCard:用户验证身份证
    User_VerifyIDCard: function (parm, callback) {
      parm = KOC.Lodash.extend({
        User_ID: null,
        IDCard: null
      }, parm);
      KOC.Async.series([
        //查看用户状态
        function (callback) {
          DALFactory.User.User_Info.Info(parm.User_ID, function (retValue) {
            if (retValue.hasError) {
              callback(retValue);
              return;
            }
            //身份证状态:-1-未上传,0-审核通过,1-待审核,2-审核驳回
            if (retValue.returnObject && KOC.Lodash.includes([0, 1], retValue.returnObject.IDCardStatus)) {
              retValue.hasError = true;
              retValue.message = "当前状态不允许";
              callback(retValue);
              return;
            }
            callback();
          });
        },
        //查看身份证是否重复
        function (callback) {
          DALFactory.User.User_Info.Info_IDCard(parm.IDCard, function (retValue) {
            if (retValue.hasError) {
              callback(retValue);
              return;
            }
            if (retValue.returnObject) {
              retValue.errorCode = 1;
              retValue.message = "身份证号重复，请重新填写";
              callback(retValue);
              return;
            }
            callback();
          });
        },
        //修改身份证号
        function (callback) {
          DALFactory.User.User_Info.Update_IDCard({
            User_ID: parm.User_ID,
            IDCard: parm.IDCard,
            IDCard_Status: 1
          }, function (retValue) {
            if (retValue.hasError) {
              callback(retValue);
              return;
            }
            callback();
          })
        }
      ], function (retValue) {
        if (retValue) {
          callback(retValue);
          return;
        }
        callback(KOC.ReturnValue.New());
      });
    },
    //endregion
    //region User_AnchorInfo:取得艺人信息
    User_AnchorInfo: function (id, callback) {
      var _AnchorInfo = null;
      KOC.Async.series([
        //读取艺人信息(ID)
        function (callback) {
          if (KOC.StringUtils.ToInt(id) <= 0) {
            callback();
            return;
          }
          DAL_Factory.User.User_Anchor.Info(id, function (retValue) {
            if (retValue.hasError) {
              callback(retValue);
              return;
            }
            if (!retValue.returnObject) {
              callback();
              return;
            }
            if (retValue.returnObject.Status !== 0) {
              retValue.hasError = true;
              retValue.message = "此艺人已经锁定";
              callback(retValue);
              return;
            }
            _AnchorInfo = retValue.returnObject;
            callback();
          });
        },
        //读取艺人信息(RoomName)
        function (callback) {
          if (_AnchorInfo) {
            callback();
            return;
          }
          DAL_Factory.User.User_Anchor.Info_RoomName(id, function (retValue) {
            if (retValue.hasError) {
              callback(retValue);
              return;
            }
            if (!retValue.returnObject) {
              retValue.hasError = true;
              retValue.message = "错误的房间号";
              callback(retValue);
              return;
            }
            if (retValue.returnObject.Status !== 0) {
              retValue.hasError = true;
              retValue.message = "此艺人已经锁定";
              callback(retValue);
              return;
            }
            _AnchorInfo = retValue.returnObject;
            callback();
          });
        }
      ], function (retValue) {
        if (retValue) {
          callback(retValue);
          return;
        }
        callback(KOC.ReturnValue.New({
          returnObject: _AnchorInfo
        }));
      });
    },
    //endregion
    //region User_AnchorHot:艺人热度
    User_AnchorHot: function (parm, callback) {
      parm = KOC.Lodash.extend({
        Type: null,
        Num: 0,
        Coin: 0,
        Value: 0,
        User_ID: null
      }, parm);
      KOC.Async.series([
        //写入初始信息
        function (callback) {
          DAL_Factory.User.User_Anchor_Hot.Insert(parm.User_ID, function (retValue) {
            if (retValue.hasError) {
              callback(retValue);
              return;
            }
            callback();
          });
        },
        //更新热度信息
        function (callback) {
          DAL_Factory.User.User_Anchor_Hot.Update({
            Type: parm.Type,
            Num: parm.Num,
            Coin: parm.Coin,
            Value: parm.Value,
            User_ID: parm.User_ID
          }, function (retValue) {
            if (retValue.hasError) {
              callback(retValue);
              return;
            }
            if (retValue.returnObject !== 1) {
              retValue.hasError = true;
              retValue.message = "更新热度信息出错，影响行(" + retValue.returnObject + ")";
              callback(retValue);
              return;
            }
            callback();
          });
        }
      ], function (retValue) {
        if (retValue) {
          callback(retValue);
          return;
        }
        callback(KOC.ReturnValue.New());
      });
    },
    //endregion
    //region User_AnchorHotNext:艺人热度切换
    User_AnchorHotNext: function (callback) {
      KOC.Async.series([
        //修改艺人热度表
        function (callback) {
          DAL_Factory.User.User_Anchor_Hot.Update_Next(function (retValue) {
            if (retValue.hasError) {
              callback(retValue);
              return;
            }
            callback();
          });
        },
        //修改艺人表
        function (callback) {
          DAL_Factory.User.User_Anchor.Update_HotValueForNext(function (retValue) {
            if (retValue.hasError) {
              callback(retValue);
              return;
            }
            callback();
          });
        }
      ], function (retValue) {
        if (retValue) {
          console.log("艺人热度切换失败:", retValue);
        }
        callback(KOC.ReturnValue.New());
      });
    },
    //endregion
    //region User_AnchorAdminSet:艺人设置管理员和移除管理员
    User_AnchorAdminSet: function (parm, callback) {
      parm = KOC.Lodash.extend({
        User_ID: null,//被操作用户ID
        User_ID_Anchor: null,//艺人ID
        Cancel: null//true:取消 false:新增
      }, parm);
      KOC.Async.series([
        //读取管理员信息
        function (callback) {
          DAL_Factory.User.User_Anchor_Admin.Info(parm.User_ID, parm.User_ID_Anchor, function (retValue) {
            if (retValue.hasError) {
              callback(retValue);
              return;
            }
            parm.IsAdmin = !!retValue.returnObject;
            callback();
          });
        },
        //插入数据，设置管理员
        function (callback) {
          if (parm.Cancel || parm.IsAdmin) {
            callback();
            return;
          }
          DAL_Factory.User.User_Anchor_Admin.Insert(parm, function (retValue) {
            if (retValue.hasError) {
              callback(retValue);
              return;
            }
            callback();
          });
        },
        //删除数据，取消管理员
        function (callback) {
          if (!parm.Cancel || !parm.IsAdmin) {
            callback();
            return;
          }
          DAL_Factory.User.User_Anchor_Admin.Delete(parm, function (retValue) {
            if (retValue.hasError) {
              callback(retValue);
              return;
            }
            callback();
          });
        }
      ], function (retValue) {
        if (retValue) {
          console.log("设置管理员失败:", retValue, parm);
          callback(retValue);
          return;
        }
        callback(KOC.ReturnValue.New());
      });
    },
    //endregion
    //region User_AnchorBlackSet:房间黑名单管理
    User_AnchorBlackSet: function (parm, callback) {
      //守护 防禁言 防踢
      parm = KOC.Lodash.extend({
        User_ID: null, //被操作用户ID
        User_ID_Admin: null, //管理员操作用户
        User_ID_Anchor: null, //艺人ID
        Type: null, //操作类型 （INT）约定：1：禁言，2：踢人，3：取消禁言，4：取消踢人
        Mode: null, //禁言或踢人,的类型，["NEVER", "YEAR", "MONTH", "WEEK", "DAY", "HOUR", "MINUTE"]
        Value: null //禁言或踢人的时间值：2 （INT）
      }, parm);
      parm.User_ID = KOC.StringUtils.ToIntPositive(parm.User_ID);
      parm.User_ID_Admin = KOC.StringUtils.ToIntPositive(parm.User_ID_Admin);
      parm.User_ID_Anchor = KOC.StringUtils.ToIntPositive(parm.User_ID_Anchor);
      if (parm.User_ID == parm.User_ID_Admin) {
        callback(KOC.ReturnValue.New({
          hasError: true,
          message: "您不可以对自己进行操作"
        }));
        return;
      }
      if (parm.User_ID == parm.User_ID_Anchor) {
        callback(KOC.ReturnValue.New({
          hasError: true,
          message: "您对本房间艺人进行操作"
        }));
        return;
      }
      if (!KOC.Lodash.includes([1, 2, 3, 4], parm.Type)) {
        callback(KOC.ReturnValue.New({
          hasError: true,
          message: "传入参数错误:Type"
        }));
        return;
      }
      if (KOC.Lodash.includes([1, 2], parm.Type) && !KOC.Lodash.includes(["NEVER", "YEAR", "MONTH", "WEEK", "DAY", "HOUR", "MINUTE"], parm.Mode)) {
        callback(KOC.ReturnValue.New({
          hasError: true,
          message: "传入参数错误:Mode"
        }));
        return;
      }
      parm.InsertUserAnchorBlackList = false;
      KOC.Async.series([
        //管理员权限
        function (callback) {
          if (parm.User_ID_Admin == parm.User_ID_Anchor) {
            callback();
            return;
          }
          DAL_Factory.User.User_Anchor_Admin.Info(parm.User_ID_Admin, parm.User_ID_Anchor, function (retValue) {
            if (retValue.hasError) {
              callback(retValue);
              return;
            }
            if (!retValue.returnObject) {
              callback(KOC.ReturnValue.New({
                hasError: true,
                message: "您不是本房间管理员,不能进行此操作"
              }));
              return;
            }
            callback();
          });
        },
        //防踢判断(房间管理员)
        function (callback) {
          if (parm.User_ID_Admin == parm.User_ID_Anchor) {
            callback();
            return;
          }
          DAL_Factory.User.User_Anchor_Admin.Info(parm.User_ID, parm.User_ID_Anchor, function (retValue) {
            if (retValue.hasError) {
              callback(retValue);
              return;
            }
            if (retValue.returnObject) {
              callback(KOC.ReturnValue.New({
                hasError: true,
                message: "此用户是本房间管理员,您不能对此用户进行黑名单操作"
              }));
              return;
            }
            callback();
          });
        },
        //防踢防禁言判断(守护)
        function (callback) {
          if (parm.User_ID_Admin == parm.User_ID_Anchor) {
            callback();
            return;
          }
          DAL_Factory.User.User_Anchor_Guardian.Info(null, parm.User_ID, parm.User_ID_Anchor, function (retValue) {
            if (retValue.hasError) {
              callback(retValue);
              return;
            }
            if (retValue.returnObject && retValue.returnObject.Guardian_ExpireStatus == 0) {
              callback(KOC.ReturnValue.New({
                hasError: true,
                message: "此用户是本房间守护,您不能对此用户进行黑名单操作"
              }));
              return;
            }
            callback();
          });
        },
        //更新房间黑名单信息
        function (callback) {
          switch (parm.Type) {
            case 1:
              //禁言
              parm.Shutup = true;
              parm.Shutup_Mode = parm.Mode;
              parm.Shutup_Value = parm.Value;
              break;
            case 2:
              //踢人
              parm.Join = true;
              parm.Join_Mode = parm.Mode;
              parm.Join_Value = parm.Value;
              break;
            case 3:
              //取消禁言
              parm.Shutup = false;
              break;
            case 4:
              //取消踢人
              parm.Join = false;
              break;
          }
          DAL_Factory.User.User_Anchor_Blacklist.Update({
            User_ID: parm.User_ID,
            User_ID_Anchor: parm.User_ID_Anchor,
            Join: parm.Join,
            Join_Mode: parm.Join_Mode,
            Join_Value: parm.Join_Value,
            Shutup: parm.Shutup,
            Shutup_Mode: parm.Shutup_Mode,
            Shutup_Value: parm.Shutup_Value
          }, function (retValue) {
            if (retValue.hasError) {
              callback(retValue);
              return;
            }
            if (retValue.returnObject !== 1 && KOC.Lodash.includes([3, 4], parm.Type)) {
              callback(KOC.ReturnValue.New({
                hasError: true,
                message: "此用户现在没有在房间黑名单列表里"
              }));
              return;
            }
            if (retValue.returnObject !== 1) {
              parm.InsertUserAnchorBlackList = true;
              callback();
              return;
            }
            callback();
          });
        },
        //写入房间黑名单信息
        function (callback) {
          if (!parm.InsertUserAnchorBlackList) {
            callback();
            return;
          }
          DAL_Factory.User.User_Anchor_Blacklist.Insert({
            User_ID: parm.User_ID,
            User_ID_Anchor: parm.User_ID_Anchor,
            Join: parm.Join,
            Join_Mode: parm.Join_Mode,
            Join_Value: parm.Join_Value,
            Shutup: parm.Shutup,
            Shutup_Mode: parm.Shutup_Mode,
            Shutup_Value: parm.Shutup_Value
          }, function (retValue) {
            if (retValue.hasError) {
              callback(retValue);
              return;
            }
            callback();
          });
        },
        //读取用户黑名单数据
        function (callback) {
          DAL_Factory.User.User_Anchor_Blacklist.Info(parm.User_ID, parm.User_ID_Anchor, function (retValue) {
            if (retValue.hasError) {
              callback(retValue);
              return;
            }
            parm.BlackInfo = retValue.returnObject;
            callback();
          });
        }
      ], function (retValue) {
        if (retValue) {
          console.log("房间黑名单操作失败:", retValue, parm);
          callback(retValue);
          return;
        }
        callback(KOC.ReturnValue.New({
          returnObject: parm.BlackInfo
        }));
      });
    },
    //endregion
    //region User_AnchorApply:艺人申请入驻
    User_AnchorApply: function (parm, callback) {
      parm = KOC.Lodash.extend({
        User_ID: null,
        Create_IP: null
      }, parm);
      if (!parm.Create_IP) {
        callback(KOC.ReturnValue.New({
          hasError: true,
          message: "用户IP不存在"
        }));
        return;
      }
      var _Conn = null;
      var _AnchorExist = true;//艺人信息是否存在，默认是存在的
      KOC.Async.series([
        //读取用户信息
        function (callback) {
          DAL_Factory.User.User_Info.Info(parm.User_ID, function (retValue) {
            if (retValue.hasError) {
              callback(retValue);
              return;
            }
            if (!retValue.returnObject) {
              retValue.hasError = true;
              retValue.message = "用户信息不存在";
              callback(retValue);
              return;
            }
            if (retValue.returnObject.IsAnchor == 1) {
              //用户已经是艺人
              retValue.hasError = true;
              retValue.message = "用户已经是艺人";
              callback(retValue);
              return;
            }
            callback();
          });
        },
        //读取艺人信息,查看状态
        function (callback) {
          DAL_Factory.User.User_Anchor.Info(parm.User_ID, function (retValue) {
            if (retValue.hasError) {
              callback(retValue);
              return;
            }
            if (!retValue.returnObject) {
              //艺人信息不存在，需要插入艺人信息
              _AnchorExist = false;
              callback();
              return;
            }
            if (retValue.returnObject.Status == 1) {
              //艺人已经被锁定
              retValue.hasError = true;
              retValue.message = "艺人已经被锁定";
              callback(retValue);
              return;
            }
            if (retValue.returnObject.Status == 2) {
              //艺人正在申请
              retValue.hasError = true;
              retValue.message = "艺人正在申请";
              callback(retValue);
              return;
            }
            callback();
          });
        },
        //读取redis信息，查看状态
        function (callback) {
          DAL_Factory.RedisCommon.UserAnchorApply.Get(parm.User_ID, function (retValue) {
            if (retValue.hasError) {
              callback(retValue);
              return;
            }
            if (!retValue.returnObject) {
              retValue.hasError = true;
              retValue.message = "redis中的艺人入驻申请信息不存在";
              callback(retValue);
              return;
            }
            //查看数据是否全
            var _index = 0;//传入参数数量
            for (var i in retValue.returnObject) {
              _index++;
            }
            if (_index < 14) {
              retValue.hasError = true;
              retValue.message = "redis中的艺人入驻申请信息不全，请重新填写";
              callback(retValue);
              return;
            }
            retValue.returnObject.User_ID = parm.User_ID;
            retValue.returnObject.Create_IP = parm.Create_IP;
            parm = KOC.Lodash.extend({
              Family_ID: null,
              Tags: null,
              Network: null,
              Account_RealName: null,
              Account_CardNo: null,
              Account_BankName: null,
              Account_BankFullName: null,
              Account_Province: null,
              Account_City: null,
              IDCard: null,
              RealName: null,
              Sex: null,
              QQ: null,
              Phone: null,
              Email: null,
              User_ID: null,
              Create_IP: null
            }, retValue.returnObject);
            var _Sex = KOC.StringUtils.ToInt(parm.Sex);
            if (_Sex > 0) {
              parm.Sex = _Sex;
            }
            var _Network = KOC.StringUtils.ToInt(parm.Network);
            if (_Network > 0) {
              parm.Network = _Network;
            }
            if (!parm.Family_ID || parm.Family_ID <= 0) {
              parm.Family_ID = null;
            }
            callback();
          });
        },
        //判断公会ID是否存在 前端判断公会是否存在之后 删除这个方法
        function (callback) {
          DAL_Factory.User.Family_Info.Info(parm.Family_ID, function (retValue) {
            if (retValue.hasError) {
              retValue.message = retValue.message;
              callback(retValue);
              return;
            }
            if (!retValue.returnObject || (retValue.returnObject && retValue.returnObject.Status != 0)) {
              //传入的公会ID不存在就当没传
              parm.Family_ID = null;
            }
            callback();
          });
        },
        //开启事物
        function (callback) {
          KOC.MysqlHelper.TranOpen(Config.Mysql.DB.User, function (retValue) {
            if (retValue.hasError) {
              callback(retValue);
              return;
            }
            _Conn = retValue.returnObject;
            callback();
          });
        },
        //更改用户表单
        function (callback) {
          DAL_Factory.User.User_Info.Update_AnchorApply(_Conn, parm, function (retValue) {
            if (retValue.hasError) {
              callback(retValue);
              return;
            }
            if (retValue.returnObject !== 1) {
              retValue.hasError = true;
              retValue.message = "写入用户登录信息出错，影响行(" + retValue.returnObject + ")";
              callback(retValue);
              return;
            }
            callback();
          });
        },
        //写入艺人表单
        function (callback) {
          if (_AnchorExist) {
            //艺人信息存在，就不插入了，直接更新
            callback();
            return;
          }
          DAL_Factory.User.User_Anchor.Insert(_Conn, {
            Family_ID: parm.Family_ID,
            Tags: parm.Tags,
            Network: parm.Network,
            Account_RealName: parm.Account_RealName,
            Account_CardNo: parm.Account_CardNo,
            Account_BankName: parm.Account_BankName,
            Account_BankFullName: parm.Account_BankFullName,
            Account_Province: parm.Account_Province,
            Account_City: parm.Account_City,
            IDCard: parm.IDCard,
            QQ: parm.QQ,
            Phone: parm.Phone,
            Email: parm.Email,
            User_ID: parm.User_ID,
            Create_IP: parm.Create_IP
          }, function (retValue) {
            if (retValue.hasError) {
              callback(retValue);
              return;
            }
            callback();
          });
        },
        //更新艺人表单
        function (callback) {
          if (!_AnchorExist) {
            //艺人信息已经插入过了，就不更新了
            callback();
            return;
          }
          DAL_Factory.User.User_Anchor.Update_Apply(_Conn, parm, function (retValue) {
            if (retValue.hasError) {
              callback(retValue);
              return;
            }
            if (retValue.returnObject !== 1) {
              retValue.hasError = true;
              retValue.message = "写入用户登录信息出错，影响行(" + retValue.returnObject + ")";
              callback(retValue);
              return;
            }
            callback();
          });
        }
      ], function (retValue) {
        if (retValue) {
          console.log("艺人申请入驻失败:", retValue, parm);
          KOC.MysqlHelper.TranRollback(_Conn, function () {
            callback(retValue);
          });
          return;
        }
        KOC.MysqlHelper.TranCommit(_Conn, function (retValue) {
          if (retValue.hasError) {
            callback(retValue);
            return;
          }
          retValue = KOC.ReturnValue.New();
          retValue.returnObject = parm;
          callback(retValue);
        });
      });
    },
    //endregion
    //region User_AnchorApplyEnter:艺人申请入驻(新)
    User_AnchorApplyEnter: function (parm, callback) {
      parm = KOC.Lodash.extend({
        User_ID: null,
        Family_ID: null,
        Tags: null,
        Network: null,
        Account_RealName: null,
        Account_CardNo: null,
        Account_BankName: null,
        Account_BankFullName: null,
        Account_Province: null,
        Account_City: null,
        RealName: null,
        Sex: null,
        QQ: null,
        Phone: null,
        Email: null,
        Create_IP: null
      }, parm);
      var _Conn = null;
      parm.AnchorExist = true;//艺人信息是否存在，默认是存在的
      KOC.Async.series([
        //读取用户信息
        function (callback) {
          DAL_Factory.User.User_Info.Info(parm.User_ID, function (retValue) {
            if (retValue.hasError) {
              callback(retValue);
              return;
            }
            if (!retValue.returnObject) {
              retValue.hasError = true;
              retValue.message = "用户信息不存在";
              callback(retValue);
              return;
            }
            if (retValue.returnObject.IsAnchor == 1) {
              //用户已经是艺人
              retValue.hasError = true;
              retValue.message = "用户已经是艺人";
              callback(retValue);
              return;
            }
            callback();
          });
        },
        //读取艺人信息,查看状态
        function (callback) {
          DAL_Factory.User.User_Anchor.Info(parm.User_ID, function (retValue) {
            if (retValue.hasError) {
              callback(retValue);
              return;
            }
            if (!retValue.returnObject) {
              //艺人信息不存在，需要插入艺人信息
              parm.AnchorExist = false;
              callback();
              return;
            }
            if (retValue.returnObject.Status == 1) {
              //艺人已经被锁定
              retValue.hasError = true;
              retValue.message = "艺人已经被锁定";
              callback(retValue);
              return;
            }
            if (retValue.returnObject.Status == 2) {
              //艺人正在申请
              retValue.hasError = true;
              retValue.message = "艺人正在申请";
              callback(retValue);
              return;
            }
            callback();
          });
        },
        //判断公会ID是否存在 前端判断公会是否存在之后 删除这个方法
        function (callback) {
          DAL_Factory.User.Family_Info.Info(parm.Family_ID, function (retValue) {
            if (retValue.hasError) {
              retValue.message = retValue.message;
              callback(retValue);
              return;
            }
            if (!retValue.returnObject || (retValue.returnObject && retValue.returnObject.Status != 0)) {
              //传入的公会ID不存在就当没传
              parm.Family_ID = null;
            }
            callback();
          });
        },
        //开启事物
        function (callback) {
          KOC.MysqlHelper.TranOpen(Config.Mysql.DB.User, function (retValue) {
            if (retValue.hasError) {
              callback(retValue);
              return;
            }
            _Conn = retValue.returnObject;
            callback();
          });
        },
        //更改用户表单
        function (callback) {
          DAL_Factory.User.User_Info.Update_AnchorApply(_Conn, {
            User_ID: parm.User_ID,
            RealName: parm.RealName,
            Sex: parm.Sex
          }, function (retValue) {
            if (retValue.hasError) {
              callback(retValue);
              return;
            }
            if (retValue.returnObject !== 1) {
              retValue.hasError = true;
              retValue.message = "写入用户登录信息出错，影响行(" + retValue.returnObject + ")";
              callback(retValue);
              return;
            }
            callback();
          });
        },
        //写入艺人表单
        function (callback) {
          if (parm.AnchorExist) {
            //艺人信息存在，就不插入了，直接更新
            callback();
            return;
          }
          DAL_Factory.User.User_Anchor.Insert(_Conn, {
            Family_ID: parm.Family_ID,
            Tags: parm.Tags,
            Network: parm.Network,
            Account_RealName: parm.Account_RealName,
            Account_CardNo: parm.Account_CardNo,
            Account_BankName: parm.Account_BankName,
            Account_BankFullName: parm.Account_BankFullName,
            Account_Province: parm.Account_Province,
            Account_City: parm.Account_City,
            QQ: parm.QQ,
            Phone: parm.Phone,
            Email: parm.Email,
            User_ID: parm.User_ID,
            Create_IP: parm.Create_IP
          }, function (retValue) {
            if (retValue.hasError) {
              callback(retValue);
              return;
            }
            callback();
          });
        },
        //更新艺人表单
        function (callback) {
          if (!parm.AnchorExist) {
            //艺人信息已经插入过了，就不更新了
            callback();
            return;
          }
          DAL_Factory.User.User_Anchor.Update_Apply(_Conn, {
            User_ID: parm.User_ID,
            Family_ID: parm.Family_ID,
            Tags: parm.Tags,
            Network: parm.Network,
            Account_RealName: parm.Account_RealName,
            Account_CardNo: parm.Account_CardNo,
            Account_BankName: parm.Account_BankName,
            Account_BankFullName: parm.Account_BankFullName,
            Account_Province: parm.Account_Province,
            Account_City: parm.Account_City,
            QQ: parm.QQ,
            Phone: parm.Phone,
            Email: parm.Email,
            Create_IP: parm.Create_IP
          }, function (retValue) {
            if (retValue.hasError) {
              callback(retValue);
              return;
            }
            if (retValue.returnObject !== 1) {
              retValue.hasError = true;
              retValue.message = "更新艺人表单出错，影响行(" + retValue.returnObject + ")";
              callback(retValue);
              return;
            }
            callback();
          });
        }
      ], function (retValue) {
        if (retValue) {
          console.log("艺人申请入驻失败:", retValue, parm);
          KOC.MysqlHelper.TranRollback(_Conn, function () {
            callback(retValue);
          });
          return;
        }
        KOC.MysqlHelper.TranCommit(_Conn, function (retValue) {
          if (retValue.hasError) {
            callback(retValue);
            return;
          }
          retValue = KOC.ReturnValue.New();
          retValue.returnObject = parm;
          callback(retValue);
        });
      });
    },
    //endregion
    // region User_AnchorApplyCheck:审批艺人申请入驻
    User_AnchorApplyCheck: function (parm, callback) {
      parm = KOC.Lodash.extend({
        User_ID: null,
        Type: null,//审批类型： 1-申请成功，2-申请失败
        Approve_Admin_ID: null,
        Approve_RealName: null,
        Duty_Admin_ID: null,
        Duty_RealName: null
      }, parm);
      if (!KOC.Lodash.includes([1, 2], parm.Type)) {
        callback(KOC.ReturnValue.New({
          hasError: true,
          message: "传入参数错误:Type"
        }));
        return;
      }
      if (!parm.Approve_Admin_ID || parm.Approve_Admin_ID <= 0) {
        callback(KOC.ReturnValue.New({
          hasError: true,
          message: "传入参数错误:Approve_Admin_ID"
        }));
        return;
      }
      var _Conn = null;
      KOC.Async.series([
        //读取艺人信息,查看状态
        function (callback) {
          DAL_Factory.User.User_Anchor.Info(parm.User_ID, function (retValue) {
            if (retValue.hasError) {
              callback(retValue);
              return;
            }
            if (!retValue.returnObject) {
              //艺人信息不存在
              retValue.hasError = true;
              retValue.message = "艺人信息不存在";
              callback(retValue);
              return;
            }
            if (retValue.returnObject.Status != 2) {
              //艺人已经被锁定
              retValue.hasError = true;
              retValue.message = "艺人信息没有处于申请状态";
              callback(retValue);
              return;
            }
            parm.Family_ID = retValue.returnObject.Family_ID ? retValue.returnObject.Family_ID : null;
            callback();
          });
        },
        //开启事物
        function (callback) {
          KOC.MysqlHelper.TranOpen(Config.Mysql.DB.User, function (retValue) {
            if (retValue.hasError) {
              callback(retValue);
              return;
            }
            _Conn = retValue.returnObject;
            callback();
          });
        },
        //修改艺人状态信息
        function (callback) {
          DAL_Factory.User.User_Anchor.Update_StatusApply(_Conn, {
            Status: parm.Type == 1 ? 0 : 3,//审批类型： 0-申请成功，3-申请失败
            User_ID: parm.User_ID
          }, function (retValue) {
            if (retValue.hasError) {
              callback(retValue);
              return;
            }
            if (retValue.returnObject !== 1) {
              retValue.hasError = true;
              retValue.message = "写入艺人状态信息，影响行(" + retValue.returnObject + ")";
              callback(retValue);
              return;
            }
            callback();
          });
        },
        //修改审批艺人管理员信息
        function (callback) {
          DAL_Factory.User.User_Anchor.Update_ApproveAdmin(_Conn, {
            User_ID: parm.User_ID,
            Approve_Admin_ID: parm.Approve_Admin_ID,//审批的管理员ID
            Approve_RealName: parm.Approve_RealName//审批的管理员姓名
          }, function (retValue) {
            if (retValue.hasError) {
              callback(retValue);
              return;
            }
            if (retValue.returnObject !== 1) {
              retValue.hasError = true;
              retValue.message = "修改审批艺人管理员信息，影响行(" + retValue.returnObject + ")";
              callback(retValue);
              return;
            }
            callback();
          });
        },
        //修改艺人责任人信息
        function (callback) {
          if (!parm.Duty_Admin_ID || parm.Duty_Admin_ID <= 0) {
            callback();
            return;
          }
          DAL_Factory.User.User_Anchor.Update_DutyAdmin(_Conn, {
            User_ID: parm.User_ID,
            Duty_Admin_ID: parm.Duty_Admin_ID,//审批的管理员ID
            Duty_RealName: parm.Duty_RealName//审批的管理员姓名
          }, function (retValue) {
            if (retValue.hasError) {
              callback(retValue);
              return;
            }
            if (retValue.returnObject !== 1) {
              retValue.hasError = true;
              retValue.message = "修改艺人责任人信息，影响行(" + retValue.returnObject + ")";
              callback(retValue);
              return;
            }
            callback();
          });
        },
        //修改用户信息
        function (callback) {
          if (parm.Type == 2) {
            callback();
            return;
          }
          DAL_Factory.User.User_Info.Update_IsAnchor(_Conn, {
            User_ID: parm.User_ID,
            Status: true
          }, function (retValue) {
            if (retValue.hasError) {
              callback(retValue);
              return;
            }
            if (retValue.returnObject !== 1) {
              retValue.hasError = true;
              retValue.message = "写入用户信息出错，影响行(" + retValue.returnObject + ")";
              callback(retValue);
              return;
            }
            callback();
          });
        },
        //修改公会艺人数量信息
        function (callback) {
          if (parm.Type == 2) {
            callback();
            return;
          }
          if (!parm.Family_ID) {
            callback();
            return;
          }
          DAL_Factory.User.Family_Info.Update_AnchorNum(_Conn, {
            Family_ID: parm.Family_ID,
            Type: 1//修改类型，1-数量加一，-1-数量减一
          }, function (retValue) {
            if (retValue.hasError) {
              callback(retValue);
              return;
            }
            if (retValue.returnObject !== 1) {
              retValue.hasError = true;
              retValue.message = "写入公会艺人数量信息出错，影响行(" + retValue.returnObject + ")";
              callback(retValue);
              return;
            }
            callback();
          });
        }
      ], function (retValue) {
        if (retValue) {
          console.log("审批艺人申请入驻失败:", retValue, parm);
          KOC.MysqlHelper.TranRollback(_Conn, function () {
            callback(retValue);
          });
          return;
        }
        KOC.MysqlHelper.TranCommit(_Conn, function (retValue) {
          if (retValue.hasError) {
            callback(retValue);
            return;
          }
          retValue = KOC.ReturnValue.New();
          retValue.returnObject = parm;
          callback(retValue);
        });
      });
    },
    //endregion
    //region User_AnchorWithdraw:艺人申请提现
    User_AnchorWithdraw: function (parm, callback) {
      parm = KOC.Lodash.extend({
        User_ID: null,//艺人ID
        Coin: null,//兑换的金豆数
        Create_IP: null
      }, parm);
      parm.Coin = parseInt(parm.Coin) ? parseInt(parm.Coin) : 0;
      //至少提现100RMB=100000金豆
      if (!parm.Coin || parm.Coin < 1000) {
        callback(KOC.ReturnValue.New({
          hasError: true,
          message: "交易金额传入错误"
        }));
        return;
      }
      //必须提现100RMB的整数倍
      if (parm.Coin % 1000 > 0) {
        callback(KOC.ReturnValue.New({
          hasError: true,
          message: "交易金额传入错误，只能兑换一百的整数倍"
        }));
        return;
      }
      var _Conn = null;
      KOC.Async.series([
        //读取用户个人信息
        function (callback) {
          DAL_Factory.User.User_Info.Info(parm.User_ID, function (retValue) {
            if (retValue.hasError) {
              callback(retValue);
              return;
            }
            if (!retValue.returnObject) {
              retValue.hasError = true;
              retValue.message = "用户不存在";
              callback(retValue);
              return;
            }
            //判断艺人
            if (retValue.returnObject.IsAnchor != 1) {
              retValue.hasError = true;
              retValue.message = "用户不是艺人身份";
              callback(retValue);
              return;
            }
            //判断时间
            if (retValue.returnObject.ApplyMoney_LastDate) {
              var last_date = retValue.returnObject.ApplyMoney_LastDate;
              var last_day = KOC.Moment(last_date).date();
              var now_day = KOC.Moment().date();
              if (KOC.Moment(last_date).year() == KOC.Moment().year() &&
                KOC.Moment(last_date).month() == KOC.Moment().month()) {
                //同年同月
                if (last_day <= 10 && now_day <= 10) {
                  retValue.hasError = true;
                  retValue.message = "上旬只能提现一次";
                  callback(retValue);
                  return;
                }
                if (last_day > 10 && last_day <= 20 && now_day > 10 && now_day <= 20) {
                  retValue.hasError = true;
                  retValue.message = "中旬只能提现一次";
                  callback(retValue);
                  return;
                }
                if (last_day > 20 && now_day > 20) {
                  retValue.hasError = true;
                  retValue.message = "下旬只能提现一次";
                  callback(retValue);
                  return;
                }
              }
            }
            //判断金豆
            if (retValue.returnObject.Beans < parm.Coin) {
              retValue.hasError = true;
              retValue.message = "用户金豆不足";
              callback(retValue);
              return;
            }
            callback();
          });
        },
        //生成单据号
        function (callback) {
          DAL_Factory.Common.Order_No_Manage.Info(CommonUtils.OrderNo.Withdraw.ID, function (retValue) {
            if (retValue.hasError) {
              callback(retValue);
              return;
            }
            if (!retValue.returnObject || !retValue.returnObject[0].Order_No) {
              retValue.hasError = true;
              retValue.message = "无此单据类型";
              callback(retValue);
              return;
            }
            parm.Order_No = retValue.returnObject[0].Order_No;
            callback();
          });
        },
        //开启事物
        function (callback) {
          KOC.MysqlHelper.TranOpen(Config.Mysql.DB.User, function (retValue) {
            if (retValue.hasError) {
              callback(retValue);
              return;
            }
            _Conn = retValue.returnObject;
            callback();
          });
        },
        //写入用户提现最新时间
        function (callback) {
          DAL_Factory.User.User_Info.Update_ApplyMoney_LastDate(_Conn, parm.User_ID, function (retValue) {
            if (retValue.hasError) {
              callback(retValue);
              return;
            }
            if (retValue.returnObject !== 1) {
              retValue.hasError = true;
              retValue.message = "写入用户提现最新时间出错，影响行(" + retValue.returnObject + ")";
              callback(retValue);
              return;
            }
            callback();
          });
        },
        //写入每日提现表
        function (callback) {
          DAL_Factory.User.Order_Withdraw.Insert(_Conn, {
            Order_No: parm.Order_No,//单据号
            User_ID: parm.User_ID,//艺人ID
            Money: parm.Coin / 10,//申请提现的金额（元）
            Revenue_Money: parm.Coin / 10 * 0.5,//税收金额（元）
            Real_Money: parm.Coin / 10 - parm.Coin / 10 * 0.5 //实际收入（元）
          }, function (retValue) {
            if (retValue.hasError) {
              callback(retValue);
              return;
            }
            callback();
          });
        },
        //扣除艺人金豆数
        function (callback) {
          DAL_Factory.Business.User_BankTransction(_Conn, {
            User_ID: parm.User_ID,
            Related_User_ID: -1,
            Related_User_NickName: "",
            Related_User_RealName: "",
            Related_Family_ID: -1,
            Related_Family_Name: "",
            Trade_Currency: 2,
            Trade_Type: 401,
            Trade_Flag: -1,
            Trade_Amt: parm.Coin,
            Trade_Order_No: parm.Order_No,
            Remark: "",
            Create_IP: parm.Create_IP
          }, function (retValue) {
            if (retValue.hasError) {
              callback(retValue);
              return;
            }
            callback();
          });
        },
      ], function (retValue) {
        if (retValue) {
          console.log("艺人申请提现失败:", retValue, parm);
          KOC.MysqlHelper.TranRollback(_Conn, function () {
            callback(retValue);
          });
          return;
        }
        KOC.MysqlHelper.TranCommit(_Conn, function (retValue) {
          if (retValue.hasError) {
            callback(retValue);
            return;
          }
          retValue = KOC.ReturnValue.New();
          retValue.returnObject = parm;
          callback(retValue);
        });
      });
    },
    //endregion
    //region User_AnchorLive:艺人开播
    User_AnchorLive: function (parm, callback) {
      parm = KOC.Lodash.extend({
        User_ID: null,
        IsMobile: null,
        Mode: null,
        RoomTitle: null,
        RoomNotice: null,
        Create_IP: null
      }, parm);
      parm.Mode = parm.IsMobile ? (KOC.Lodash.includes([11, 12], parm.Mode) ? parm.Mode : 11) : 0;
      var _Conn = null;
      var _LiveEnd = false;
      KOC.Async.series([
        //读取用户信息
        function (callback) {
          DAL_Factory.User.User_Info.Info(parm.User_ID, function (retValue) {
            if (retValue.hasError) {
              callback(retValue);
              return;
            }
            if (!retValue.returnObject.IsAnchor) {
              retValue.hasError = true;
              retValue.message = "非艺人帐号,不能开播";
              callback(retValue);
              return;
            }
            if (!retValue.returnObject) {
              retValue.hasError = true;
              retValue.message = "用户不存在";
              callback(retValue);
              return;
            }
            parm.User_NickName = retValue.returnObject.NickName;
            parm.User_RealName = retValue.returnObject.RealName;
            callback();
          });
        },
        //读取艺人信息
        function (callback) {
          DAL_Factory.User.User_Anchor.Info(parm.User_ID, function (retValue) {
            if (retValue.hasError) {
              callback(retValue);
              return;
            }
            if (!retValue.returnObject) {
              retValue.hasError = true;
              retValue.message = "无此艺人信息,用户不是艺人身份";
              callback(retValue);
              return;
            }
            if (retValue.returnObject.Status != 0) {
              retValue.hasError = true;
              retValue.message = "此艺人已被锁定";
              callback(retValue);
              return;
            }
            parm.Family_ID = retValue.returnObject.Family_ID;
            _LiveEnd = retValue.returnObject.Live;
            callback();
          });
        },
        //结束现有直播
        function (callback) {
          if (!_LiveEnd) {
            callback();
            return;
          }
          DAL_Factory.Business.User_AnchorLiveEnd(parm.User_ID, function (retValue) {
            if (retValue.hasError) {
              callback(retValue);
              return;
            }
            callback();
          });
        },
        //读取公会信息
        function (callback) {
          if (!parm.Family_ID || parm.Family_ID < 0) {
            parm.Family_ID = -1;
            parm.Family_Name = "";
            callback();
            return;
          }
          DAL_Factory.User.Family_Info.Info(parm.Family_ID, function (retValue) {
            if (retValue.hasError) {
              callback(retValue);
              return;
            }
            if (!retValue.returnObject) {
              retValue.hasError = true;
              retValue.message = "无此公会信息";
              callback(retValue);
              return;
            }
            parm.Family_Name = retValue.returnObject.Family_Name;
            callback();
          });
        },
        //生成单据号
        function (callback) {
          DAL_Factory.Common.Order_No_Manage.Info(CommonUtils.OrderNo.Live.ID, function (retValue) {
            if (retValue.hasError) {
              callback(retValue);
              return;
            }
            if (!retValue.returnObject || !retValue.returnObject[0].Order_No) {
              retValue.hasError = true;
              retValue.message = "无此单据类型";
              callback(retValue);
              return;
            }
            parm.Order_No = retValue.returnObject[0].Order_No;
            callback();
          });
        },
        //开启事物
        function (callback) {
          KOC.MysqlHelper.TranOpen(Config.Mysql.DB.User, function (retValue) {
            if (retValue.hasError) {
              callback(retValue);
              return;
            }
            _Conn = retValue.returnObject;
            callback();
          });
        },
        //写入直播单据
        function (callback) {
          DAL_Factory.User.Order_Live.Insert(_Conn, {
            Order_No: parm.Order_No,
            User_ID: parm.User_ID,
            User_NickName: parm.User_NickName,
            User_RealName: parm.User_RealName,
            Family_ID: parm.Family_ID,
            Family_Name: parm.Family_Name,
            IsMobile: parm.IsMobile,
            Mode: parm.Mode,
            Create_IP: parm.Create_IP
          }, function (retValue) {
            if (retValue.hasError) {
              callback(retValue);
              return;
            }
            callback();
          });
        },
        //更新艺人信息
        function (callback) {
          DAL_Factory.User.User_Anchor.Update_Live(_Conn, {
            User_ID: parm.User_ID,
            Live_IsMobile: parm.IsMobile,
            Live_Mode: parm.Mode,
            Live_Order_No: parm.Order_No,
            RoomTitle: parm.RoomTitle,
            RoomNotice: parm.RoomNotice
          }, function (retValue) {
            if (retValue.hasError) {
              callback(retValue);
              return;
            }
            if (retValue.returnObject !== 1) {
              retValue.hasError = true;
              retValue.message = "更新艺人信息单出错，影响行(" + retValue.returnObject + ")";
              callback(retValue);
              return;
            }
            callback();
          });
        }
      ], function (retValue) {
        if (retValue) {
          console.log("开播失败:", retValue, parm);
          KOC.MysqlHelper.TranRollback(_Conn, function () {
            callback(retValue);
          });
          return;
        }
        KOC.MysqlHelper.TranCommit(_Conn, function (retValue) {
          if (retValue.hasError) {
            callback(retValue);
            return;
          }
          retValue = KOC.ReturnValue.New();
          retValue.returnObject = parm;
          callback(retValue);
        });
      });
    },
    //endregion
    //region User_AnchorLiveEnd:艺人直播结束
    User_AnchorLiveEnd: function (User_ID, callback) {
      var parm = {
        User_ID: User_ID
      };
      var _Conn = null;
      KOC.Async.series([
        //读取艺人信息
        function (callback) {
          DAL_Factory.User.User_Anchor.Info(parm.User_ID, function (retValue) {
            if (retValue.hasError) {
              callback(retValue);
              return;
            }
            if (!retValue.returnObject) {
              retValue.hasError = true;
              retValue.message = "无此艺人信息,用户不是艺人身份";
              callback(retValue);
              return;
            }
            if (!retValue.returnObject.Live) {
              retValue.hasError = true;
              retValue.message = "艺人没有进行直播";
              callback(retValue);
              return;
            }
            parm.Order_No = retValue.returnObject.Live_Order_No;
            callback();
          });
        },
        //开启事物
        function (callback) {
          KOC.MysqlHelper.TranOpen(Config.Mysql.DB.User, function (retValue) {
            if (retValue.hasError) {
              callback(retValue);
              return;
            }
            _Conn = retValue.returnObject;
            callback();
          });
        },
        //更新直播单据表信息
        function (callback) {
          DAL_Factory.User.Order_Live.Update_End(_Conn, {
            Order_No: parm.Order_No,
            User_ID: parm.User_ID
          }, function (retValue) {
            if (retValue.hasError) {
              callback(retValue);
              return;
            }
            if (retValue.returnObject !== 1) {
              retValue.hasError = true;
              retValue.message = "更新艺人信息单出错，影响行(" + retValue.returnObject + ")";
              callback(retValue);
              return;
            }
            callback();
          });
        },
        //更新艺人信息
        function (callback) {
          DAL_Factory.User.User_Anchor.Update_LiveEnd(_Conn, {
            User_ID: parm.User_ID
          }, function (retValue) {
            if (retValue.hasError) {
              callback(retValue);
              return;
            }
            if (retValue.returnObject !== 1) {
              retValue.hasError = true;
              retValue.message = "更新艺人信息单出错，影响行(" + retValue.returnObject + ")";
              callback(retValue);
              return;
            }
            callback();
          });
        },
        //重置本场贡献值
        function (callback) {
          DAL_Factory.User.User_Contribution.Update_Live(_Conn, parm.User_ID, function (retValue) {
            if (retValue.hasError) {
              callback(retValue);
              return;
            }
            callback();
          });
        }
      ], function (retValue) {
        if (retValue) {
          console.log("结束播放失败:", retValue, parm);
          KOC.MysqlHelper.TranRollback(_Conn, function () {
            callback(retValue);
          });
          return;
        }
        KOC.MysqlHelper.TranCommit(_Conn, function (retValue) {
          if (retValue.hasError) {
            callback(retValue);
            return;
          }
          retValue = KOC.ReturnValue.New();
          retValue.returnObject = parm;
          callback(retValue);
        });
      });
    },
    //endregion
    //region User_AnchorMoveFamily:艺人转公会
    User_AnchorMoveFamily: function (parm, callback) {
      parm = KOC.Lodash.extend({
        User_ID: null,//艺人ID
        Family_ID: null//公会ID
      }, parm);
      parm.User_ID = KOC.StringUtils.ToInt(parm.User_ID, -1);
      parm.Family_ID = KOC.StringUtils.ToInt(parm.Family_ID, -1);
      if (parm.User_ID < 0) {
        callback(KOC.ReturnValue.New({
          hasError: true,
          message: "参数传入错误" + parm.User_ID
        }));
        return;
      }
      var _Conn = null;
      KOC.Async.series([
        //读取用户个人信息
        function (callback) {
          DAL_Factory.User.User_Info.Info(parm.User_ID, function (retValue) {
            if (retValue.hasError) {
              callback(retValue);
              return;
            }
            if (!retValue.returnObject) {
              retValue.hasError = true;
              retValue.message = "用户不存在";
              callback(retValue);
              return;
            }
            //判断艺人
            if (retValue.returnObject.IsAnchor != 1) {
              retValue.hasError = true;
              retValue.message = "用户不是艺人身份";
              callback(retValue);
              return;
            }
            callback();
          });
        },
        //读取公会信息
        function (callback) {
          if (parm.Family_ID < 0) {
            callback();
            return;
          }
          DAL_Factory.User.Family_Info.Info(parm.Family_ID, function (retValue) {
            if (retValue.hasError) {
              callback(retValue);
              return;
            }
            if (!retValue.returnObject) {
              retValue.hasError = true;
              retValue.message = "公会信息不存在";
              callback(retValue);
              return;
            }
            //判断公会信息
            if (retValue.returnObject.Status > 1) {
              retValue.hasError = true;
              retValue.message = "公会不存在";
              callback(retValue);
              return;
            }
            if (parm.User_ID == retValue.returnObject.User_ID) {
              retValue.hasError = true;
              retValue.message = "公会长不可以转公会";
              callback(retValue);
              return;
            }
            callback();
          });
        },
        //读取艺人公会信息
        function (callback) {
          DAL_Factory.User.User_Anchor.Info(parm.User_ID, function (retValue) {
            if (retValue.hasError) {
              callback(retValue);
              return;
            }
            if (!retValue.returnObject) {
              retValue.hasError = true;
              retValue.message = "艺人信息不存在";
              callback(retValue);
              return;
            }
            if (retValue.returnObject.Family_ID && parm.Family_ID > 0 && retValue.returnObject.Family_ID == parm.Family_ID) {
              retValue.hasError = true;
              retValue.message = "艺人已经是当前公会艺人";
              callback(retValue);
              return;
            }
            if ((!retValue.returnObject.Family_ID || retValue.returnObject.Family_ID < 0) && parm.Family_ID < 0) {
              retValue.hasError = true;
              retValue.message = "艺人已经平台艺人";
              callback(retValue);
              return;
            }
            parm.Anchor_FamilyID = KOC.StringUtils.ToInt(retValue.returnObject.Family_ID, -1);
            callback();
          });
        },
        //开启事物
        function (callback) {
          KOC.MysqlHelper.TranOpen(Config.Mysql.DB.User, function (retValue) {
            if (retValue.hasError) {
              callback(retValue);
              return;
            }
            _Conn = retValue.returnObject;
            callback();
          });
        },
        //修改艺人公会ID
        function (callback) {
          DAL_Factory.User.User_Anchor.Update_FamilyID(_Conn, {
            User_ID: parm.User_ID,
            Family_ID: parm.Family_ID > 0 ? parm.Family_ID : null
          }, function (retValue) {
            if (retValue.hasError) {
              callback(retValue);
              return;
            }
            if (retValue.returnObject !== 1) {
              retValue.hasError = true;
              retValue.message = "修改艺人公会ID出错，影响行(" + retValue.returnObject + ")";
              callback(retValue);
              return;
            }
            callback();
          });
        },
        //修改原公会艺人数量
        function (callback) {
          if (parm.Anchor_FamilyID < 0) {
            callback();
            return;
          }
          DAL_Factory.User.Family_Info.Update_AnchorNum(_Conn, {
            Family_ID: parm.Anchor_FamilyID,
            Type: -1//修改类型，1-数量加一，-1-数量减一
          }, function (retValue) {
            if (retValue.hasError) {
              callback(retValue);
              return;
            }
            if (retValue.returnObject !== 1) {
              retValue.hasError = true;
              retValue.message = "修改原公会艺人数量出错，影响行(" + retValue.returnObject + ")";
              callback(retValue);
              return;
            }
            callback();
          });
        },
        //修改新公会艺人数量
        function (callback) {
          if (!parm.Family_ID || parm.Family_ID <= 0) {
            callback();
            return;
          }
          DAL_Factory.User.Family_Info.Update_AnchorNum(_Conn, {
            Family_ID: parm.Family_ID,
            Type: 1//修改类型，1-数量加一，-1-数量减一
          }, function (retValue) {
            if (retValue.hasError) {
              callback(retValue);
              return;
            }
            if (retValue.returnObject !== 1) {
              retValue.hasError = true;
              retValue.message = "修改新公会艺人数量出错，影响行(" + retValue.returnObject + ")";
              callback(retValue);
              return;
            }
            callback();
          });
        }
      ], function (retValue) {
        if (retValue) {
          console.log("艺人转公会失败:", retValue, parm);
          KOC.MysqlHelper.TranRollback(_Conn, function () {
            callback(retValue);
          });
          return;
        }
        KOC.MysqlHelper.TranCommit(_Conn, function (retValue) {
          if (retValue.hasError) {
            callback(retValue);
            return;
          }
          retValue = KOC.ReturnValue.New();
          retValue.returnObject = parm;
          callback(retValue);
        });
      });
    },
    //endregion
    //region User_AnchorCoverPut:上传图片
    User_AnchorCoverPut: function (parm, callback) {
      parm = KOC.Lodash.extend({
        User_ID: null,
        NickName: null,
        ImageName: null,//图片的名称
        Type: null,
        Create_IP: null
      }, parm);
      var _Conn = null;
      parm.ImageExist = true;
      parm.OldImage = null;
      parm.Type = KOC.StringUtils.ToIntPositive(parm.Type);
      if (!KOC.Lodash.includes([1, 2], parm.Type)) {
        callback(KOC.ReturnValue.New({
          hasError: true,
          message: "传入参数错误:Type"
        }));
        return;
      }
      KOC.Async.series([
        //获取图片信息
        function (callback) {
          DAL_Factory.User.User_Anchor_Cover.Info({
            User_ID: parm.User_ID,
            Type: parm.Type
          }, function (retValue) {
            if (retValue.hasError) {
              callback(retValue);
              return;
            }
            if (!retValue.returnObject) {
              parm.ImageExist = false;
            }
            parm.OldImage = retValue.returnObject &&
            retValue.returnObject.Image &&
            retValue.returnObject.Status == 1 ?
              retValue.returnObject.Image : null;
            callback();
          });
        },
        //开启事物
        function (callback) {
          KOC.MysqlHelper.TranOpen(Config.Mysql.DB.User, function (retValue) {
            if (retValue.hasError) {
              callback(retValue);
              return;
            }
            _Conn = retValue.returnObject;
            callback();
          });
        },
        //修改图片的信息
        function (callback) {
          if (!parm.ImageExist) {
            //图片信息不存在
            callback();
            return;
          }
          DAL_Factory.User.User_Anchor_Cover.Update_Image(_Conn, {
            User_ID: parm.User_ID,
            Image: parm.ImageName,
            Type: parm.Type
          }, function (retValue) {
            if (retValue.hasError) {
              callback(retValue);
              return;
            }
            callback();
          });
        },
        //插入图片信息
        function (callback) {
          if (parm.ImageExist) {
            //图片信息存在
            callback();
            return;
          }
          DAL_Factory.User.User_Anchor_Cover.Insert(_Conn, {
            User_ID: parm.User_ID,
            NickName: parm.NickName,
            Image: parm.ImageName,
            Type: parm.Type,
            Create_IP: parm.Create_IP
          }, function (retValue) {
            if (retValue.hasError) {
              callback(retValue);
              return;
            }
            callback();
          });
        },
        //提交事务
        function (callback) {
          KOC.MysqlHelper.TranCommit(_Conn, function (retValue) {
            _Conn = null;
            if (retValue.hasError) {
              callback(retValue);
              return;
            }
            callback();
          });
        }
      ], function (retValue) {
        if (retValue) {
          console.log("申请审核图片失败:", retValue);
          KOC.MysqlHelper.TranRollback(_Conn, function () {
            callback(retValue);
          });
          return;
        }
        callback(KOC.ReturnValue.New({
          returnObject: parm
        }));
      });
    },
    //endregion
    //region User_AnchorCoverPut:审核艺人封面
    User_AnchorCoverCheck: function (parm, callback) {
      parm = KOC.Lodash.extend({
        Admin_ID: null,//管理员ID
        User_ID: null,
        Type: null,
        Status: null,//审批类型：0-申请成功，2-申请失败
        Create_IP: null
      }, parm);
      var _Conn = null;
      KOC.Async.series([
        //获取艺人海报信息
        function (callback) {
          DAL_Factory.User.User_Anchor_Cover.Info({
            User_ID: parm.User_ID,
            Type: parm.Type
          }, function (retValue) {
            if (retValue.hasError) {
              callback(retValue);
              return;
            }
            if (!retValue.returnObject) {
              callback(KOC.ReturnValue.New({
                hasError: true,
                errorCode: 2,
                message: "该用户图片信息不存在"
              }));
              return;
            }
            if (retValue.returnObject.Status != 1) {
              callback(KOC.ReturnValue.New({
                hasError: true,
                errorCode: 2,
                message: "该用户图片信息状态不是待审核"
              }));
              return;
            }
            parm.ImageName = retValue.returnObject.Image;
            callback();
          });
        },
        //查询管理员信息
        function (callback) {
          DAL_Factory.User.User_Admin.Info(parm.Admin_ID, function (retValue) {
            if (retValue.hasError) {
              callback(retValue);
              return;
            }
            if (!retValue.returnObject) {
              retValue.hasError = true;
              retValue.message = '没有该管理员信息';
              return;
            }
            parm.RealName = retValue.returnObject.RealName;
            parm.Phone = retValue.returnObject.Phone;
            callback();
          });
        },
        //开启事物
        function (callback) {
          KOC.MysqlHelper.TranOpen(Config.Mysql.DB.User, function (retValue) {
            if (retValue.hasError) {
              callback(retValue);
              return;
            }
            _Conn = retValue.returnObject;
            callback();
          });
        },
        //修改艺人海报表的状态
        function (callback) {
          DAL_Factory.User.User_Anchor_Cover.Update_Status(_Conn, {
            User_ID: parm.User_ID,
            Type: parm.Type,
            Status: parseInt(parm.Status)
          }, function (retValue) {
            if (retValue.hasError) {
              callback(retValue);
              return;
            }
            callback();
          });
        },
        //修改审核艺人海报管理员信息
        function (callback) {
          if (parm.Type == 2) {
            callback();
            return;
          }
          DAL_Factory.User.User_Anchor.Update_CoverAdmin(_Conn, {
            User_ID: parm.User_ID,
            Cover_Admin_ID: parm.Admin_ID,//审批的管理员ID
            Cover_RealName: parm.RealName//审批的管理员姓名
          }, function (retValue) {
            if (retValue.hasError) {
              callback(retValue);
              return;
            }
            if (retValue.returnObject !== 1) {
              retValue.hasError = true;
              retValue.message = "修改审核艺人海报管理员信息，影响行(" + retValue.returnObject + ")";
              callback(retValue);
              return;
            }
            callback();
          });
        },
        //添加log
        function (callback) {
          if (parm.Type == 2) {
            callback();
            return;
          }
          DAL_Factory.Log.Admin_Log.Insert({
            Log_Type: 2,
            Operate_Type: 1,
            Operation: "艺人封面审核",
            Related_ID: parm.User_ID,
            Data: '修改了艺人ID:' + parm.User_ID + '的封面',
            Admin_ID: parm.Admin_ID,
            RealName: parm.RealName,
            Phone: parm.Phone,
            Create_IP: parm.Create_IP
          }, function (retValue) {
            if (retValue.hasError) {
              callback(retValue);
              return;
            }
            if (retValue.returnObject !== 1) {
              retValue.hasError = true;
              retValue.message = "添加员工信息数据出错，影响行(" + retValue.returnObject + ")";
              callback(retValue);
              return;
            }
            callback();
          });
        },
        //提交事务
        function (callback) {
          KOC.MysqlHelper.TranCommit(_Conn, function (retValue) {
            _Conn = null;
            if (retValue.hasError) {
              callback(retValue);
              return;
            }
            callback();
          });
        }
      ], function (retValue) {
        if (retValue) {
          console.log("申请审核用户图片报失败:", retValue);
          KOC.MysqlHelper.TranRollback(_Conn, function () {
            callback(retValue);
          });
          return;
        }
        callback(KOC.ReturnValue.New({
          returnObject: parm
        }));
      });
    },
    //endregion
    //region User_AnchorIntegralUpdate:艺人罚分
    User_AnchorIntegralUpdate: function (parm, callback) {
      parm = KOC.Lodash.extend({
        User_ID_Admin: null,//管理员ID
        User_NickName_Admin: null,//操作人昵称
        User_RealName_Admin: null,//操作艺人真实姓名
        User_ID: null,//用户ID
        Integral: null,//罚分
        Type: null,//类型
        Operation: null,//操作类型:-1-警告,1-结束直播,2-冻结房间
        Inform: null,//通知类型:-1-默认不通知,1-通知艺人自己,2-通知房间内所有用户,3-通知全服
        Remark: null,//说明
        Create_IP: null
      }, parm);
      var _Conn = null;
      parm.User_ID = KOC.StringUtils.ToIntPositive(parm.User_ID);
      parm.User_ID_Admin = KOC.StringUtils.ToIntPositive(parm.User_ID_Admin);
      parm.Integral = KOC.StringUtils.ToIntPositive(parm.Integral);
      parm.Operation = KOC.StringUtils.ToIntPositive(parm.Operation);
      parm.Inform = KOC.StringUtils.ToIntPositive(parm.Inform);
      //验证用户ID
      if (!parm.User_ID) {
        callback(KOC.ReturnValue.New({
          hasError: true,
          message: "参数错误 User_ID：" + parm.User_ID
        }));
        return;
      }
      //验证管理员ID
      if (!parm.User_ID_Admin) {
        callback(KOC.ReturnValue.New({
          hasError: true,
          message: "参数错误 User_ID_Admin：" + parm.User_ID_Admin
        }));
        return;
      }
      //验证通知类型
      if (!KOC.Lodash.includes([0, 1, 2, 3], parm.Inform)) {
        callback(KOC.ReturnValue.New({
          hasError: true,
          message: "参数错误 Inform：" + parm.Inform
        }));
        return;
      }
      //验证操作类型
      if (!KOC.Lodash.includes([0, 1, 2], parm.Operation)) {
        callback(KOC.ReturnValue.New({
          hasError: true,
          message: "参数错误 Operation：" + parm.Operation
        }));
        return;
      }
      KOC.Async.series([
        //读取被操作用户信息
        function (callback) {
          DAL_Factory.User.User_Info.Info(parm.User_ID, function (retValue) {
            if (retValue.hasError) {
              callback(retValue);
              return;
            }
            if (!retValue.returnObject) {
              retValue.hasError = true;
              retValue.message = "用户不存在";
              callback(retValue);
              return;
            }
            parm.User_NickName = retValue.returnObject.NickName;
            parm.User_RealName = retValue.returnObject.RealName;
            callback();
          });
        },
        //读取艺人信息
        function (callback) {
          DAL_Factory.User.User_Anchor.Info(parm.User_ID, function (retValue) {
            if (retValue.hasError) {
              callback(retValue);
              return;
            }
            if (!retValue.returnObject) {
              retValue.hasError = true;
              retValue.message = "无此艺人信息";
              callback(retValue);
              return;
            }
            parm.Family_ID = retValue.returnObject.Family_ID;
            callback();
          });
        },
        //获取艺人公会信息
        function (callback) {
          if (parm.Family_ID <= 0) {
            callback();
            return;
          }
          DAL_Factory.User.Family_Info.Info(parm.Family_ID, function (retValue) {
            if (retValue.hasError) {
              callback(retValue);
              return;
            }
            if (!retValue.returnObject) {
              retValue.hasError = true;
              retValue.message = "无艺人公会信息";
              callback(retValue);
              return;
            }
            parm.Family_Name = retValue.returnObject.Family_Name;
            callback();
          });
        },
        //生成单据号
        function (callback) {
          DAL_Factory.Common.Order_No_Manage.Info(CommonUtils.OrderNo.Integral.ID, function (retValue) {
            if (retValue.hasError) {
              callback(retValue);
              return;
            }
            if (!retValue.returnObject || !retValue.returnObject[0].Order_No) {
              retValue.hasError = true;
              retValue.message = "无此单据类型";
              callback(retValue);
              return;
            }
            parm.Order_No = retValue.returnObject[0].Order_No;
            callback();
          });
        },
        //开启事物
        function (callback) {
          KOC.MysqlHelper.TranOpen(Config.Mysql.DB.User, function (retValue) {
            if (retValue.hasError) {
              callback(retValue);
              return;
            }
            _Conn = retValue.returnObject;
            callback();
          });
        },
        //更新艺人罚分信息
        function (callback) {
          if (!parm.Integral) {
            callback();
            return;
          }
          DAL_Factory.User.User_Anchor.Update_Integral(_Conn, {
            User_ID: parm.User_ID,//艺人ID
            Integral: parm.Integral//罚分值
          }, function (retValue) {
            if (retValue.hasError) {
              callback(retValue);
              return;
            }
            if (retValue.returnObject !== 1) {
              retValue.hasError = true;
              retValue.message = "更新艺人罚分信息出错，影响行(" + retValue.returnObject + ")";
              callback(retValue);
              return;
            }
            callback();
          });
        },
        //插入艺人罚分单据
        function (callback) {
          DAL_Factory.User.Order_Integral.Insert(_Conn, {
            Order_No: parm.Order_No,//单据号
            User_ID: parm.User_ID,//被操作艺人ID
            User_NickName: parm.User_NickName,//被操作艺人昵称
            User_RealName: parm.User_RealName,//被操作艺人真实姓名
            User_ID_Admin: parm.User_ID_Admin,//操作人ID
            User_NickName_Admin: parm.User_NickName_Admin,//操作人昵称
            User_RealName_Admin: parm.User_RealName_Admin,//操作人真实姓名
            Family_ID: parm.Family_ID,//艺人公会ID
            Family_Name: parm.Family_Name,//艺人公会名称
            Integral: parm.Integral,//罚分
            Type: parm.Type,//类型
            Operation: parm.Operation,//操作类型:-1-警告,1-结束直播,2-冻结房间
            Inform: parm.Inform,//通知类型:-1-默认不通知,1-通知艺人自己,2-通知房间内所有用户,3-通知全服
            Remark: parm.Remark,//说明
            Create_IP: parm.Create_IP
          }, function (retValue) {
            if (retValue.hasError) {
              callback(retValue);
              return;
            }
            callback();
          });
        },
        //提交事务
        function (callback) {
          KOC.MysqlHelper.TranCommit(_Conn, function (retValue) {
            _Conn = null;
            if (retValue.hasError) {
              callback(retValue);
              return;
            }
            callback();
          });
        }
      ], function (retValue) {
        if (retValue) {
          console.log("艺人罚分失败:", retValue);
          KOC.MysqlHelper.TranRollback(_Conn, function () {
            callback(retValue);
          });
          return;
        }
        callback(KOC.ReturnValue.New({
          returnObject: {
            Order_No: parm.Order_No,
            Integral: parm.Integral,
            Operation: parm.Operation,
            Inform: parm.Inform
          }
        }))
        ;
      });
    },
    //endregion
    //region User_AnchorSearch:艺人搜索
    User_AnchorSearch: function (parm, callback) {
      parm = KOC.Lodash.extend({
        IsSearch: null,//是否需要查询
        SearchValue: null,//查询信息
        Limit: null,//默认50条
        IsHotList: null,//是否需要热门列表,类型Bool,默认需要
        HotLimit: null //默认5条
      }, parm);
      parm.IsSearch = KOC.StringUtils.ToInt(parm.IsSearch, 1);
      parm.SearchValue = KOC.StringUtils.ToString(parm.SearchValue).replace(/ /g, "").replace(/　/g, "");
      parm.IsHotList = KOC.StringUtils.ToInt(parm.IsHotList, 1);
      parm.HotLimit = KOC.StringUtils.ToInt(parm.HotLimit, 5);
      if (parm.IsSearch && (!parm.SearchValue || parm.SearchValue == "")) {
        callback(KOC.ReturnValue.New({
          hasError: true,
          message: "请输入正确的查询信息"
        }));
        return;
      }
      KOC.Async.series([
        //获取艺人列表
        function (callback) {
          if (!parm.IsSearch) {
            parm.AnchorList = [];
            callback();
            return;
          }
          DAL_Factory.User.User_Anchor.List_Search_J({
            Cache: true,
            Limit: parm.Limit,
            FuzzyQuery: parm.SearchValue
          }, function (retValue) {
            if (retValue.hasError) {
              callback(retValue);
              return;
            }
            parm.AnchorList = [];
            if (!retValue.returnObject || retValue.returnObject.length == 0) {
              callback();
              return;
            }
            KOC.Lodash.forEach(retValue.returnObject, function (ThisValue) {
              ThisValue = KOC.Lodash.pick(ThisValue, [
                "User_ID",
                "RoomName",
                "RoomWelcome",
                "RoomTemplate",
                "RoomTitle",
                "RoomNotice",
                "Family_ID",
                "Tags",
                "Anchor_EXP",
                "Level",
                "Level_Name",
                "Level_Next",
                "Level_Next_Name",
                "EXP_Next",
                "EXP_Difference",
                "Anchor_Level",
                "Anchor_Level_Name",
                "Anchor_Level_Next",
                "Anchor_Level_Next_Name",
                "Anchor_EXP_Next",
                "Anchor_EXP_Difference",
                "HotValue_Ranking",
                "HotValue",
                "ActivityNum",
                "Anchor_Pomelo",
                "Anchor_Pomelo_Today",
                "Anchor_Pomelo_Week",
                "Anchor_Pomelo_Month",
                "Anchor_Pomelo_Year",
                "Live",
                "Live_FirstDate",
                "Live_IsMobile",
                "Live_Mode",
                "Live_Order_No",
                "Live_StartTime",
                "Live_Duration_Total",
                "Live_Stream_LastDate",
                "Live_Stream_Status",
                "Network",
                "IsWeekStar",
                "IsRecommend",
                "ProtectDue_Date",
                "Rating",
                "Rating_Date",
                "Integral",
                "Integral_Month",
                "Integral_Month_Last",
                "Integral_Week",
                "Integral_Week_Last",
                "Integral_Date",
                "List_Order",
                "Create_Date",
                "Create_IP",
                "Status",
                "NickName",
                "Signature",
                "Sex",
                "EXP",
                "Fans",
                "Attention",
                "IsFamily",
                "IsAnchor",
                "Coin" +
                "Coin_Today" +
                "Coin_Week" +
                "Coin_Month" +
                "Coin_Year" +
                "Coin_Total" +
                "Beans",
                "Beans_Today",
                "Beans_Week",
                "Beans_Month",
                "Beans_Year",
                "Beans_Total",
                "ApplyMoney_LastDate ",
                "Family_Name",
                "Family_UserID",
                "Hot_Value_Previous",
                "Hot_Value"
              ]);
              parm.AnchorList.push(ThisValue);
            });
            callback();
          });
        },
        //获取热门艺人列表
        function (callback) {
          if (!parm.IsHotList) {
            parm.AnchorHotList = [];
            callback();
            return;
          }
          DAL_Factory.RedisCommon.UserAnchorListHot.Get(0, parm.HotLimit, function (retValue) {
            if (retValue.hasError) {
              callback(retValue);
              return;
            }
            parm.AnchorHotList = retValue.returnObject;
            callback();
          });
        }
      ], function (retValue) {
        if (retValue) {
          callback(retValue);
          return;
        }
        callback(KOC.ReturnValue.New({
          returnObject: {
            IsSearch: parm.IsSearch,
            SearchValue: parm.SearchValue,
            Limit: parm.Limit,
            IsHotList: parm.IsHotList,
            HotLimit: parm.HotLimit,
            AnchorList: parm.AnchorList,
            AnchorHotList: parm.AnchorHotList
          }
        }));
      });
    },
    //endregion
    //region User_RoomReset:房间服务重启
    User_RoomReset: function (callback) {
      var _List = null;
      KOC.Async.series([
        //取得所有直播列表
        function (callback) {
          DAL_Factory.User.User_Anchor.List_Live(function (retValue) {
            if (retValue.hasError) {
              callback(retValue);
              return;
            }
            if (retValue.returnObject && retValue.returnObject.length > 0) {
              _List = retValue.returnObject;
            }
            callback();
          });
        },
        //结束所有直播放
        function (callback) {
          if (!_List) {
            callback();
            return;
          }
          KOC.Async.each(_List, function (ThisValue, callback) {
            DAL_Factory.Business.User_AnchorLiveEnd(ThisValue.User_ID, function (retValue) {
              if (retValue.hasError) {
                callback(retValue);
                return;
              }
              callback();
            });
          }, function (retValue) {
            callback(retValue);
          });
        },
        //清空Redis数据
        function (callback) {
          DAL_Factory.RedisRoom.Clear();
          callback();
        }
      ], function (retValue) {
        if (retValue) {
          console.log("结束播放失败[ALL]:", retValue);
          callback(retValue);
        }
        callback(KOC.ReturnValue.New());
      });
    },
    //endregion
    //region User_AdminCurrencyUpdate:后台管理修改用户或公会的金币或金豆
    User_AdminCurrencyUpdate: function (parm, callback) {
      parm = KOC.Lodash.extend({
        Admin_ID: null,
        Related_Type: null,
        Related_ID: null,
        Trade_Flag: null,
        Trade_Currency: null,
        Trade_Amt: null,
        Remark: null,
        Create_IP: null
      }, parm);
      parm.Related_Type = KOC.StringUtils.ToInt(parm.Related_Type, -2);
      parm.Trade_Flag = KOC.StringUtils.ToInt(parm.Trade_Flag, -2);
      parm.Trade_Currency = KOC.StringUtils.ToInt(parm.Trade_Currency, -2);
      parm.Trade_Amt = KOC.StringUtils.ToInt(parm.Trade_Amt, -2);
      //相关类型：1-用户，2-公会
      if (!KOC.Lodash.includes([1, 2], parm.Related_Type)) {
        callback(KOC.ReturnValue.New({
          hasError: true,
          message: "传入参数错误:Related_Type"
        }));
        return;
      }
      //交易方式  1：入账-1：出账
      if (!KOC.Lodash.includes([1, -1], parm.Trade_Flag)) {
        callback(KOC.ReturnValue.New({
          hasError: true,
          message: "传入参数错误:Trade_Flag"
        }));
        return;
      }
      //交易币种1:金币 2:金豆
      if (!KOC.Lodash.includes([1, 2], parm.Trade_Currency)) {
        callback(KOC.ReturnValue.New({
          hasError: true,
          message: "传入参数错误:Trade_Currency"
        }));
        return;
      }
      //交易金额
      if (!parm.Trade_Amt || parm.Trade_Amt <= 0) {
        callback(KOC.ReturnValue.New({
          hasError: true,
          message: "传入参数错误:Trade_Amt"
        }));
        return;
      }
      var _Conn = null;
      KOC.Async.series([
        //读取管理员信息
        function (callback) {
          DAL_Factory.User.User_Info.Info(parm.Admin_ID, function (retValue) {
            if (retValue.hasError) {
              callback(retValue);
              return;
            }
            if (!retValue.returnObject) {
              retValue.hasError = true;
              retValue.message = "用户不存在";
              callback(retValue);
              return;
            }
            parm.NickName = retValue.returnObject.NickName;
            parm.RealName = retValue.returnObject.RealName;
            callback();
          });
        },
        //读取被操作用户信息
        function (callback) {
          if (parm.Related_Type == 2) {
            callback();
            return;
          }
          DAL_Factory.User.User_Info.Info(parm.Related_ID, function (retValue) {
            if (retValue.hasError) {
              callback(retValue);
              return;
            }
            if (!retValue.returnObject) {
              retValue.hasError = true;
              retValue.message = "用户不存在";
              callback(retValue);
              return;
            }
            parm.Related_NickName = retValue.returnObject.NickName;
            callback();
          });
        },
        //读取被操作公会信息
        function (callback) {
          if (parm.Related_Type == 1) {
            callback();
            return;
          }
          DAL_Factory.User.Family_Info.Info(parm.Related_ID, function (retValue) {
            if (retValue.hasError) {
              callback(retValue);
              return;
            }
            if (!retValue.returnObject) {
              retValue.hasError = true;
              retValue.message = "无此公会信息";
              callback(retValue);
              return;
            }
            parm.Related_NickName = retValue.returnObject.Family_Name;
            callback();
          });
        },
        //生成单据号
        function (callback) {
          DAL_Factory.Common.Order_No_Manage.Info(CommonUtils.OrderNo.BankManage.ID, function (retValue) {
            if (retValue.hasError) {
              callback(retValue);
              return;
            }
            if (!retValue.returnObject || !retValue.returnObject[0].Order_No) {
              retValue.hasError = true;
              retValue.message = "无此单据类型";
              callback(retValue);
              return;
            }
            parm.Order_No = retValue.returnObject[0].Order_No;
            callback();
          });
        },
        //开启事物
        function (callback) {
          KOC.MysqlHelper.TranOpen(Config.Mysql.DB.User, function (retValue) {
            if (retValue.hasError) {
              callback(retValue);
              return;
            }
            _Conn = retValue.returnObject;
            callback();
          });
        },
        //写入帐户资金管理表(管理员操作)
        function (callback) {
          DAL_Factory.User.Order_BankManage.Insert(_Conn, {
            Order_No: parm.Order_No,//提现单据号
            Admin_ID: parm.Admin_ID,//操作用户ＩＤ
            NickName: parm.NickName,//操作用户昵称
            RealName: parm.RealName,//操作用户真实姓名
            Related_Type: parm.Related_Type,//相关类型：1-用户，2-公会
            Related_ID: parm.Related_ID,//相关ID（用户ID 或公会ID）
            Related_NickName: parm.Related_NickName,//相关名称（用户昵称或公会名称）
            Trade_Flag: parm.Trade_Flag,//交易方式  1：入账-1：出账
            Trade_Currency: parm.Trade_Currency,// 交易币种1:金币 2:金豆
            Trade_Amt: parm.Trade_Amt,//交易金额
            Remark: parm.Remark,//备注
            Create_IP: parm.Create_IP//IP地址
          }, function (retValue) {
            if (retValue.hasError) {
              callback(retValue);
              return;
            }
            callback();
          });
        },
        //写入用户帐户资金交易表
        function (callback) {
          if (parm.Related_Type == 2) {
            callback();
            return;
          }
          DAL_Factory.Business.User_BankTransction(_Conn, {
            User_ID: parm.Related_ID,
            Related_User_ID: parm.Admin_ID,
            Related_User_NickName: parm.NickName,
            Related_User_RealName: parm.RealName,
            Related_Family_ID: -1,
            Related_Family_Name: "",
            Trade_Currency: parm.Trade_Currency,
            Trade_Type: parm.Trade_Flag == 1 ? (parm.Trade_Currency == 1 ? 105 : 204) : (parm.Trade_Currency == 1 ? 306 : 403),
            Trade_Flag: parm.Trade_Flag,
            Trade_Amt: parm.Trade_Amt,
            Trade_Order_No: parm.Order_No,
            Remark: parm.Remark,
            Create_IP: parm.Create_IP
          }, function (retValue) {
            if (retValue.hasError) {
              callback(retValue);
              return;
            }
            callback();
          });
        },
        //写入公会帐户资金交易(豆)表
        function (callback) {
          if (parm.Related_Type == 1) {
            callback();
            return;
          }
          DAL_Factory.Business.User_FamilyBankTransction(_Conn, {
            Family_ID: parm.Related_ID,
            Related_User_ID: parm.Admin_ID,
            Related_User_NickName: parm.NickName,
            Related_User_RealName: parm.RealName,
            Related_Anchor_ID: -1,
            Related_Anchor_NickName: "",
            Related_Anchor_RealName: "",
            Trade_Type: parm.Trade_Flag == 1 ? 204 : 403,
            Trade_Flag: parm.Trade_Flag,
            Trade_Amt: parm.Trade_Amt,
            Trade_Order_No: parm.Order_No,
            Remark: parm.Remark,
            Create_IP: parm.Create_IP
          }, function (retValue) {
            if (retValue.hasError) {
              callback(retValue);
              return;
            }
            callback();
          });
        }
      ], function (retValue) {
        if (retValue) {
          console.log("台管理修改用户或公会的金币或金豆失败:", retValue, parm);
          KOC.MysqlHelper.TranRollback(_Conn, function () {
            callback(retValue);
          });
          return;
        }
        KOC.MysqlHelper.TranCommit(_Conn, function (retValue) {
          if (retValue.hasError) {
            callback(retValue);
            return;
          }
          retValue = KOC.ReturnValue.New();
          retValue.returnObject = parm;
          callback(retValue);
        });
      });
    },
    //endregion
    //region User_WeekStarRank:礼物榜单
    User_WeekStarRank: function (parm, callback) {
      parm = KOC.Lodash.extend({
        Gift_ID: null,//礼物ID
        Length: null,//请求个数
        Type: null,//请求类型：1-艺人周星榜，2-粉丝周星榜
        Week: null, //请求类型：1-本周， 2-上周, 3-大上周， 4-大大上周， 5-特殊日期
        StartTime: null,
        EndTime: null
      }, parm);
      parm.Gift_ID = KOC.StringUtils.ToInt(parm.Gift_ID, -1);
      parm.Length = KOC.StringUtils.ToInt(parm.Length, 0);
      parm.Type = KOC.StringUtils.ToInt(parm.Type, -1);
      parm.Week = KOC.StringUtils.ToInt(parm.Week, -1);
      var GiftList = CommonUtils.Commodity.Gift.Data;
      var WeekStart_GiftList = [];
      parm.WeekStar = 1;//周星榜标识：1-是周星榜，2-是勇者大冲关榜,3-是特殊活动
      //处理时间
      var days = 7 * (parm.Week - 1);
      parm.Create_Date_Between = KOC.Moment().subtract(days, 'days').startOf('week')._d;
      parm.Create_Date_And = KOC.Moment().subtract(days, 'days').endOf('week')._d;
      for (var index in GiftList) {
        if (GiftList[index].IsWeekStar) {
          WeekStart_GiftList.push(GiftList[index].id);
        } else if (GiftList[index].IsActivity) {
          WeekStart_GiftList.push(GiftList[index].id);
        }
        if (parm.Gift_ID == GiftList[index].id && GiftList[index].IsActivity) {
          parm.WeekStar = 2;
          parm.Create_Date_Between = KOC.Moment().subtract(days, 'days').startOf('week').add(1, 'days')._d;
          parm.Create_Date_And = KOC.Moment().subtract(days, 'days').endOf('week').add(1, 'days')._d;
        }
        if (parm.Gift_ID == GiftList[index].id) {
          if (GiftList[index].IsWeekStar) {
            if (GiftList[index].WeekStarMin < 0) {
              callback(KOC.ReturnValue.New({
                hasError: true,
                message: "传入参数错误:WeekStarMin"
              }));
              return;
            }
            parm.WeekStarMin = GiftList[index].WeekStarMin;
            parm.WeekStarAward = GiftList[index].WeekStarAward;
          }
          parm.Gift_Name = GiftList[index].Name;
        }
      }
      if (!KOC.Lodash.includes(WeekStart_GiftList, parm.Gift_ID)) {
        callback(KOC.ReturnValue.New({
          hasError: true,
          message: "传入参数错误:Gift_ID"
        }));
        return;
      }
      if (!KOC.Lodash.includes([1, 2], parm.Type)) {
        callback(KOC.ReturnValue.New({
          hasError: true,
          message: "传入参数错误:Type"
        }));
        return;
      }
      if (!KOC.Lodash.includes([1, 2, 3, 4, 5], parm.Week)) {
        callback(KOC.ReturnValue.New({
          hasError: true,
          message: "传入参数错误:Week"
        }));
        return;
      }
      if (parm.Week == 5 && (!parm.StartTime || !parm.EndTime)) {
        callback(KOC.ReturnValue.New({
          hasError: true,
          message: "传入参数错误:Time"
        }));
        return;
      }
      if (parm.Length <= 0) {
        callback(KOC.ReturnValue.New({
          hasError: true,
          message: "传入参数错误:Length"
        }));
        return;
      }
      //特殊日期处理
      if (parm.Week == 5) {
        parm.WeekStar = 3;
        parm.Create_Date_Between = KOC.Moment(new Date(parm.StartTime)).startOf('day')._d;
        parm.Create_Date_And = KOC.Moment(new Date(parm.EndTime)).endOf('day')._d;
      }
      KOC.Async.series([
        //读取艺人周星榜
        function (callback) {
          if (parm.Type == 2) {
            callback();
            return;
          }
          DAL_Factory.User.Order_Gift.Info_WeekStarAnchor({
            Gift_ID: parm.Gift_ID,
            Length: parm.Length,
            Create_Date_Between: parm.Create_Date_Between,
            Create_Date_And: parm.Create_Date_And
          }, function (retValue) {
            if (retValue.hasError) {
              callback(retValue);
              return;
            }
            if (!retValue.returnObject) {
              retValue.hasError = true;
              retValue.message = "艺人周星榜数据不存在";
              callback(retValue);
              return;
            }
            parm.Rank = retValue.returnObject;
            callback();
          });
        },
        //读取艺人等级
        function (callback) {
          if (parm.Type == 2) {
            callback();
            return;
          }
          for (var index in parm.Rank) {
            var _LevelInfo = CommonUtils.Anchor.Level.fnLevel(parm.Rank[index].EXP);
            parm.Rank[index].Level_Name = _LevelInfo.Name;
            parm.Rank[index].Level = _LevelInfo.Level;
          }
          callback();
        },
        //读取粉丝周星榜
        function (callback) {
          if (parm.Type == 1) {
            callback();
            return;
          }
          DAL_Factory.User.Order_Gift.Info_WeekStarFans({
            Gift_ID: parm.Gift_ID,
            Length: parm.Length,
            Create_Date_Between: parm.Create_Date_Between,
            Create_Date_And: parm.Create_Date_And
          }, function (retValue) {
            if (retValue.hasError) {
              callback(retValue);
              return;
            }
            if (!retValue.returnObject) {
              retValue.hasError = true;
              retValue.message = "粉丝周星榜数据不存在";
              callback(retValue);
              return;
            }
            parm.Rank = retValue.returnObject;
            callback();
          });
        },
        //读取用户等级
        function (callback) {
          if (parm.Type == 1) {
            callback();
            return;
          }
          for (var index in parm.Rank) {
            var _LevelInfo = CommonUtils.User.Level.fnLevel(parm.Rank[index].EXP);
            parm.Rank[index].Level_Name = _LevelInfo.Name;
            parm.Rank[index].Level = _LevelInfo.Level;
          }
          callback();
        }
      ], function (retValue) {
        if (retValue) {
          callback(retValue);
          return;
        }
        retValue = KOC.ReturnValue.New();
        retValue.returnObject = parm;
        callback(retValue);
      });
    },
    //endregion
    //region User_WeekStarRankAll:获取周星榜全部
    User_WeekStarRankAll: function (parm, callback) {
      parm = KOC.Lodash.extend({
        Week: null, //请求类型：1-本周， 2-上周, 3-大上周， 4-大大上周， 5-特殊日期
        Length: null//请求个数
      }, parm);
      var GiftList = CommonUtils.Commodity.Gift.Data;
      var WeekStart_GiftList = [];
      parm.Week = KOC.StringUtils.ToInt(parm.Week, -1);
      if (!KOC.Lodash.includes([1, 2], parm.Week)) {
        callback(KOC.ReturnValue.New({
          hasError: true,
          message: "传入参数错误:Week"
        }));
        return;
      }
      for (var index in GiftList) {
        if (GiftList[index].IsWeekStar && GiftList[index].Status == 0) {
          if (parm.Week == 1) {
            WeekStart_GiftList.push({
              Gift_ID: GiftList[index].id,//礼物ID
              Length: parm.Length,//请求个数
              Type: 1,//请求类型：1-艺人周星榜，2-粉丝周星榜
              Week: 1 //请求类型：1-本周， 2-上周, 3-大上周， 4-大大上周， 5-特殊日期
            });
            WeekStart_GiftList.push({
              Gift_ID: GiftList[index].id,//礼物ID
              Length: parm.Length,//请求个数
              Type: 2,//请求类型：1-艺人周星榜，2-粉丝周星榜
              Week: 1 //请求类型：1-本周， 2-上周, 3-大上周， 4-大大上周， 5-特殊日期
            });
          } else {
            WeekStart_GiftList.push({
              Gift_ID: GiftList[index].id,//礼物ID
              Length: parm.Length,//请求个数
              Type: 1,//请求类型：1-艺人周星榜，2-粉丝周星榜
              Week: 2 //请求类型：1-本周， 2-上周, 3-大上周， 4-大大上周， 5-特殊日期
            });
            WeekStart_GiftList.push({
              Gift_ID: GiftList[index].id,//礼物ID
              Length: parm.Length,//请求个数
              Type: 2,//请求类型：1-艺人周星榜，2-粉丝周星榜
              Week: 2 //请求类型：1-本周， 2-上周, 3-大上周， 4-大大上周， 5-特殊日期
            });
          }
        }
      }
      //获取榜单信息
      KOC.Async.each(WeekStart_GiftList, function (ThisValue, callback) {
        DAL_Factory.Business.User_WeekStarRank({
          Gift_ID: ThisValue.Gift_ID,//礼物ID
          Length: ThisValue.Length,//请求个数
          Type: ThisValue.Type,//请求类型：1-艺人周星榜，2-粉丝周星榜
          Week: ThisValue.Week //请求类型：1-本周， 2-上周, 3-大上周， 4-大大上周， 5-特殊日期
        }, function (retValue) {
          if (retValue.hasError) {
            callback(retValue);
            return;
          }
          //数据处理
          for (var key in WeekStart_GiftList) {
            if (WeekStart_GiftList[key].Gift_ID == retValue.returnObject.Gift_ID
              && WeekStart_GiftList[key].Type == retValue.returnObject.Type
              && WeekStart_GiftList[key].Week == retValue.returnObject.Week) {
              WeekStart_GiftList[key].Gift_Name = retValue.returnObject.Gift_Name;
              WeekStart_GiftList[key].Rank = retValue.returnObject.Rank;
              WeekStart_GiftList[key].WeekStarMin = retValue.returnObject.WeekStarMin;
              WeekStart_GiftList[key].WeekStarAward = retValue.returnObject.WeekStarAward;
            }
          }
          callback();
        });
      }, function (retValue) {
        if (retValue) {
          callback(retValue);
          return;
        }
        retValue = KOC.ReturnValue.New();
        retValue.returnObject = WeekStart_GiftList;
        callback(retValue);
      });
    },
    //endregion
    //region User_CurrencyExchange:豆币兑换
    User_CurrencyExchange: function (parm, callback) {
      parm = KOC.Lodash.extend({
        User_ID: null,//用户ID
        Beans: null,//兑换的金豆数量
        Create_IP: null//用户IP
      }, parm);
      parm.User_ID = KOC.StringUtils.ToInt(parm.User_ID, -1);
      parm.Beans = KOC.StringUtils.ToInt(parm.Beans, -1) == parm.Beans ? KOC.StringUtils.ToInt(parm.Beans, -1) : -1;
      if (parm.User_ID < 0) {
        callback(KOC.ReturnValue.New({
          hasError: true,
          message: "参数传入错误" + parm.User_ID
        }));
        return;
      }
      if (parm.Beans <= 0) {
        callback(KOC.ReturnValue.New({
          hasError: true,
          message: "参数传入错误" + parm.Beans
        }));
        return;
      }
      var _Conn = null;
      KOC.Async.series([
        //读取用户个人信息
        function (callback) {
          DAL_Factory.User.User_Info.Info(parm.User_ID, function (retValue) {
            if (retValue.hasError) {
              callback(retValue);
              return;
            }
            if (!retValue.returnObject) {
              retValue.hasError = true;
              retValue.message = "用户不存在";
              callback(retValue);
              return;
            }
            //判断用户金豆数
            if (retValue.returnObject.Beans < parm.Beans) {
              retValue.hasError = true;
              retValue.message = "金豆不足";
              callback(retValue);
              return;
            }
            parm.NickName = retValue.returnObject.NickName;
            parm.RealName = retValue.returnObject.RealName;
            callback();
          });
        },
        //生成单据号
        function (callback) {
          DAL_Factory.Common.Order_No_Manage.Info(CommonUtils.OrderNo.CurrencyExchange.ID, function (retValue) {
            if (retValue.hasError) {
              callback(retValue);
              return;
            }
            if (!retValue.returnObject || !retValue.returnObject[0].Order_No) {
              retValue.hasError = true;
              retValue.message = "无此单据类型";
              callback(retValue);
              return;
            }
            parm.Order_No = retValue.returnObject[0].Order_No;
            callback();
          });
        },
        //开启事物
        function (callback) {
          KOC.MysqlHelper.TranOpen(Config.Mysql.DB.User, function (retValue) {
            if (retValue.hasError) {
              callback(retValue);
              return;
            }
            _Conn = retValue.returnObject;
            callback();
          });
        },
        //写入豆币兑换的交易表
        function (callback) {
          DAL_Factory.User.Order_CurrencyExchange.Insert(_Conn, {
            Order_No: parm.Order_No,
            User_ID: parm.User_ID,
            NickName: parm.NickName,
            RealName: parm.RealName,
            Exchange_Beans: parm.Beans,
            Exchange_Coin: parm.Beans,
            Create_IP: parm.Create_IP
          }, function (retValue) {
            if (retValue.hasError) {
              callback(retValue);
              return;
            }
            callback();
          });
        },
        //写入用户帐户资金交易表，扣金豆
        function (callback) {
          DAL_Factory.Business.User_BankTransction(_Conn, {
            User_ID: parm.User_ID,
            Related_User_ID: parm.User_ID,
            Related_User_NickName: parm.NickName,
            Related_User_RealName: parm.RealName,
            Related_Family_ID: -1,
            Related_Family_Name: "",
            Trade_Currency: 2,
            Trade_Type: 404,
            Trade_Flag: -1,
            Trade_Amt: parm.Beans,
            Trade_Order_No: parm.Order_No,
            Remark: "",
            Create_IP: parm.Create_IP
          }, function (retValue) {
            if (retValue.hasError) {
              callback(retValue);
              return;
            }
            callback();
          });
        },
        //写入用户帐户资金交易表，添加金币
        function (callback) {
          DAL_Factory.Business.User_BankTransction(_Conn, {
            User_ID: parm.User_ID,
            Related_User_ID: parm.User_ID,
            Related_User_NickName: parm.NickName,
            Related_User_RealName: parm.RealName,
            Related_Family_ID: -1,
            Related_Family_Name: "",
            Trade_Currency: 1,
            Trade_Type: 106,
            Trade_Flag: 1,
            Trade_Amt: parm.Beans,
            Trade_Order_No: parm.Order_No,
            Remark: "",
            Create_IP: parm.Create_IP
          }, function (retValue) {
            if (retValue.hasError) {
              callback(retValue);
              return;
            }
            callback();
          });
        },
      ], function (retValue) {
        if (retValue) {
          console.log("豆币兑换失败:", retValue, parm);
          KOC.MysqlHelper.TranRollback(_Conn, function () {
            callback(retValue);
          });
          return;
        }
        KOC.MysqlHelper.TranCommit(_Conn, function (retValue) {
          if (retValue.hasError) {
            callback(retValue);
            return;
          }
          retValue = KOC.ReturnValue.New();
          retValue.returnObject = parm;
          callback(retValue);
        });
      });
    },
    //endregion
    //region User_FeedBack:用户意见反馈
    User_FeedBack: function (parm, callback) {
      parm = KOC.Lodash.extend({
        User_ID: null,
        Relate_User_ID: null,
        Relate_NickName: null,
        Type: null,
        QQ: null,
        Message: null,
        Create_IP: null
      }, parm);
      DAL_Factory.User.User_FeedBack.Insert({
        User_ID: parm.User_ID,
        Relate_User_ID: parm.Relate_User_ID,
        Relate_NickName: parm.Relate_NickName,
        Type: parm.Type,
        QQ: parm.QQ,
        Message: parm.Message,
        Create_IP: parm.Create_IP
      }, function (retValue) {
        if (retValue.hasError) {
          callback(retValue);
          return;
        }
        retValue = KOC.ReturnValue.New();
        retValue.returnObject = parm;
        callback(retValue);
      });
    },
    //endregion
    //region User_AdminItemGrant:后台发放物品
    User_AdminItemGrant: function (parm, callback) {
      parm = KOC.Lodash.extend({
        Admin_ID: null,
        Item_Type: null,//被操作的类型
        User_ID: null,//被操作的用户
        User_NickName: null,
        Item_ID: null,
        Item_Name: null,
        Item_Expire: null,
        Num: null,
        Remark: null,
        Create_IP: null
      }, parm);
      parm.Item_Type = KOC.StringUtils.ToInt(parm.Item_Type, -1);
      if (!KOC.Lodash.includes([1, 2], parm.Item_Type)) {
        callback(KOC.ReturnValue.New({
          hasError: true,
          message: "传入参数错误:Item_Type"
        }));
        return;
      }
      var _Conn = null;
      KOC.Async.series([
        //读取操作用户个人信息
        function (callback) {
          DAL_Factory.User.User_Info.Info(parm.Admin_ID, function (retValue) {
            if (retValue.hasError) {
              callback(retValue);
              return;
            }
            if (!retValue.returnObject) {
              retValue.hasError = true;
              retValue.message = "用户不存在";
              callback(retValue);
              return;
            }
            callback();
          });
        },
        //读取被操作用户个人信息
        function (callback) {
          DAL_Factory.User.User_Info.Info(parm.User_ID, function (retValue) {
            if (retValue.hasError) {
              callback(retValue);
              return;
            }
            if (!retValue.returnObject) {
              retValue.hasError = true;
              retValue.message = "用户不存在";
              callback(retValue);
              return;
            }
            callback();
          });
        },
        //开启事物
        function (callback) {
          KOC.MysqlHelper.TranOpen(Config.Mysql.DB.User, function (retValue) {
            if (retValue.hasError) {
              callback(retValue);
              return;
            }
            _Conn = retValue.returnObject;
            callback();
          });
        },
        //插入后台发放物品记录表
        function (callback) {
          DAL_Factory.User.User_ItemGrant.Insert(_Conn, {
            User_ID: parm.User_ID,
            User_NickName: parm.User_NickName,
            Item_Type: parm.Item_Type,
            Item_ID: parm.Item_ID,
            Item_Name: parm.Item_Name,
            Num: parm.Num,
            Item_Expire: parm.Item_Expire,
            Remark: parm.Remark,
            Create_IP: parm.Create_IP
          }, function (retValue) {
            if (retValue.hasError) {
              callback(retValue);
              return;
            }
            callback();
          });
        },
        //修改座驾信息
        function (callback) {
          if (parm.Item_Type != 2) {
            callback();
            return;
          }
          DAL_Factory.User.User_Mounts.Insert(_Conn, {
            User_ID: parm.User_ID,
            Mounts_ID: parm.Item_ID,
            Mounts_Mode: "DAY",
            Mounts_Value: parm.Item_Expire,
            Mounts_Name: parm.Item_Name,
            Create_IP: parm.Create_IP
          }, function (retValue) {
            if (retValue.hasError) {
              callback(retValue);
              return;
            }
            callback();
          });
        },
        //修改VIP信息
        function (callback) {
          if (parm.Item_Type != 1) {
            callback();
            return;
          }
          DAL_Factory.User.User_Info.Update_VIP(_Conn, {
            VIP_Mode: "DAY",
            VIP_Value: parm.Item_Expire,
            User_ID: parm.User_ID
          }, function (retValue) {
            if (retValue.hasError) {
              callback(retValue);
              return;
            }
            if (retValue.returnObject !== 1) {
              retValue.hasError = true;
              retValue.message = "更新用户VIP信息出错，影响行(" + retValue.returnObject + ")";
              callback(retValue);
              return;
            }
            callback();
          });
        },
        //放入包裹 礼物(未完成)
        function (callback) {
          if (parm.Item_Type != 3) {
            callback();
            return;
          }
          //包裹交易单有问题，先不做后台的礼物发放
          callback();
          DAL_Factory.Business.User_PackageTransction(_Conn, {
            User_ID: parm.User_ID,
            Item_Type: "Gift",
            Item_ID: parm.Item_ID,
            Trade_Type: 0,
            Trade_Flag: 1,
            Trade_Num: 0,
            Trade_Order_No: "",//充值订单号
            Remark: "",
            Create_IP: parm.Create_IP
          }, function (retValue) {
            if (retValue.hasError) {
              callback(retValue);
              return;
            }
            callback();
          });
        },
      ], function (retValue) {
        if (retValue) {
          console.log("后台发放物品失败:", retValue, parm);
          KOC.MysqlHelper.TranRollback(_Conn, function () {
            callback(retValue);
          });
          return;
        }
        KOC.MysqlHelper.TranCommit(_Conn, function (retValue) {
          if (retValue.hasError) {
            callback(retValue);
            return;
          }
          retValue = KOC.ReturnValue.New();
          retValue.returnObject = parm;
          callback(retValue);
        });
      });
    },
    //endregion
    //region User_Lottery:用户抽奖
    User_Lottery: function (parm, callback) {
      parm = KOC.Lodash.extend({
        User_ID: null,//用户ID
        User_ID_Anchor: null,//直播间ID
        Lottery_ID: null,//抽奖ID
        Create_IP: null
      }, parm);
      parm.User_ID = KOC.StringUtils.ToInt(parm.User_ID, -1);
      parm.User_ID_Anchor = KOC.StringUtils.ToInt(parm.User_ID_Anchor, -1);
      parm.Lottery_ID = KOC.StringUtils.ToInt(parm.Lottery_ID, -1);
      //获取抽奖配置信息
      parm.Lottery = CommonUtils.Lottery.fnInfo(parm.Lottery_ID);
      if (parm.User_ID <= 0) {
        callback(KOC.ReturnValue.New({
          hasError: true,
          message: "传入参数错误:User_ID"
        }));
        return;
      }
      if (parm.User_ID_Anchor <= 0) {
        callback(KOC.ReturnValue.New({
          hasError: true,
          message: "传入参数错误:User_ID_Anchor"
        }));
        return;
      }
      if (parm.Lottery_ID <= 0) {
        callback(KOC.ReturnValue.New({
          hasError: true,
          message: "传入参数错误:Lottery_ID"
        }));
        return;
      }
      if (!parm.Lottery || parm.Lottery.Status != 0) {
        callback(KOC.ReturnValue.New({
          hasError: true,
          message: "抽奖的配置信息出错,请联系管理员"
        }));
        return;
      }
      var _Conn = null;
      KOC.Async.series([
        //读取用户个人信息
        function (callback) {
          DAL_Factory.User.User_Info.Info(parm.User_ID, function (retValue) {
            if (retValue.hasError) {
              callback(retValue);
              return;
            }
            if (!retValue.returnObject) {
              retValue.hasError = true;
              retValue.message = "用户不存在";
              callback(retValue);
              return;
            }
            if (retValue.returnObject.Coin < parm.Lottery.Price) {
              retValue.hasError = true;
              retValue.errorCode = -2;
              retValue.message = "金币不足,请及时充值";
              callback(retValue);
              return;
            }
            parm.User_NickName = retValue.returnObject.NickName;
            parm.User_RealName = retValue.returnObject.RealName;
            callback();
          });
        },
        //读取艺人信息
        function (callback) {
          DAL_Factory.User.User_Anchor.Info(parm.User_ID_Anchor, function (retValue) {
            if (retValue.hasError) {
              callback(retValue);
              return;
            }
            if (!retValue.returnObject) {
              retValue.hasError = true;
              retValue.message = "无此艺人信息";
              callback(retValue);
              return;
            }
            parm.Family_ID = retValue.returnObject.Family_ID ? retValue.returnObject.Family_ID : -1;
            callback();
          });
        },
        //读取艺人公会信息
        function (callback) {
          if (!parm.Family_ID || parm.Family_ID < 0) {
            parm.Family_Name = "";
            callback();
            return;
          }
          DAL_Factory.User.Family_Info.Info(parm.Family_ID, function (retValue) {
            if (retValue.hasError) {
              callback(retValue);
              return;
            }
            if (!retValue.returnObject) {
              retValue.hasError = true;
              retValue.message = "无此公会信息";
              callback(retValue);
              return;
            }
            parm.Family_Name = retValue.returnObject.Family_Name;
            callback();
          });
        },
        //生成单据号
        function (callback) {
          DAL_Factory.Common.Order_No_Manage.Info(CommonUtils.OrderNo.Lottery.ID, function (retValue) {
            if (retValue.hasError) {
              callback(retValue);
              return;
            }
            if (!retValue.returnObject || !retValue.returnObject[0].Order_No) {
              retValue.hasError = true;
              retValue.message = "无此单据类型";
              callback(retValue);
              return;
            }
            parm.Order_No = retValue.returnObject[0].Order_No;
            callback();
          });
        },
        //开启事物
        function (callback) {
          KOC.MysqlHelper.TranOpen(Config.Mysql.DB.User, function (retValue) {
            if (retValue.hasError) {
              callback(retValue);
              return;
            }
            _Conn = retValue.returnObject;
            callback();
          });
        },
        //写入用户资金交易记录（扣除抽奖金币）
        function (callback) {
          DAL_Factory.Business.User_BankTransction(_Conn, {
            User_ID: parm.User_ID,
            Related_User_ID: -1,
            Related_User_NickName: "",
            Related_User_RealName: "",
            Related_Family_ID: -1,
            Related_Family_Name: "",
            Trade_Currency: 1,
            Trade_Type: 307,
            Trade_Flag: -1,//扣除用户金币
            Trade_Amt: parm.Lottery.Price,
            Trade_Order_No: parm.Order_No,
            Remark: "用户抽奖-花费金币",
            Create_IP: parm.Create_IP
          }, function (retValue) {
            if (retValue.hasError) {
              callback(retValue);
              return;
            }
            callback();
          });
        },
        //写入抽奖单据表
        function (callback) {
          DAL_Factory.User.Order_Lottery.Insert(_Conn, {
            Order_No: parm.Order_No, //单据号
            User_ID: parm.User_ID, //用户ID
            User_NickName: parm.User_NickName, //用户昵称
            User_RealName: parm.User_RealName, //用户真实姓名
            User_ID_Anchor: parm.User_ID_Anchor, //用户ID(艺人，房间)
            Family_ID: parm.Family_ID, //公会ID
            Family_Name: parm.Family_Name, //公会名称
            Order_Amt: parm.Lottery.Price, //抽奖金额(金币)
            Count: parm.Lottery.Count, //抽奖次数
            Category: parm.Lottery.Category, //抽奖类别
            Create_IP: parm.Create_IP //IP地址
          }, function (retValue) {
            if (retValue.hasError) {
              callback(retValue);
              return;
            }
            callback();
          });
        },
        //进行抽奖
        function (callback) {
          DAL_Factory.User.Lottery_Info.Update_Proc(_Conn, parm.Order_No, function (retValue) {
            if (retValue.hasError) {
              callback(retValue);
              return;
            }
            if (!retValue.returnObject || !retValue.returnObject.length || retValue.returnObject.length == 0) {
              retValue.hasError = true;
              retValue.message = "抽奖过程错误";
              callback(retValue);
              return;
            }
            parm.WinningList = retValue.returnObject;
            callback();
          });
        },
        //按照中奖类型进行奖励发放
        function (callback) {
          KOC.Async.each(parm.WinningList, function (ThisValue, callback) {
            switch (ThisValue.Item_Type) {
              case "COIN": //金币
                DAL_Factory.Business.User_BankTransction(_Conn, {
                  User_ID: parm.User_ID,
                  Related_User_ID: -1,
                  Related_User_NickName: "",
                  Related_User_RealName: "",
                  Related_Family_ID: -1,
                  Related_Family_Name: "",
                  Trade_Currency: 1,
                  Trade_Type: 108,
                  Trade_Flag: 1,
                  Trade_Amt: ThisValue.Item_Value,
                  Trade_Order_No: parm.Order_No,
                  Remark: "用户抽奖-获得金币",
                  Create_IP: parm.Create_IP
                }, function (retValue) {
                  callback(retValue.hasError ? retValue : null);
                });
                return;
              case "EXP": //经验
                DAL_Factory.User.User_Info.Update_EXP(_Conn, {
                  EXP: ThisValue.Item_Value,
                  User_ID: parm.User_ID
                }, function (retValue) {
                  if (retValue.hasError) {
                    callback(retValue);
                    return;
                  }
                  if (retValue.returnObject !== 1) {
                    retValue.hasError = true;
                    retValue.message = "抽奖验奖励出错(影响" + retValue.returnObject + "行)";
                    callback(retValue);
                    return;
                  }
                  callback();
                });
                return;
              case "POMELO": //星星
                DAL_Factory.User.User_Info.Update_Pomelo(_Conn, parm.User_ID, ThisValue.Item_Value, function (retValue) {
                  if (retValue.hasError) {
                    callback(retValue);
                    return;
                  }
                  if (retValue.returnObject !== 1) {
                    retValue.hasError = true;
                    retValue.message = "抽奖星星出错(影响" + retValue.returnObject + "行)";
                    callback(retValue);
                    return;
                  }
                  callback();
                });
                return;
              case "GIFT": //礼物
                DAL_Factory.Business.User_PackageTransction(_Conn, {
                  User_ID: parm.User_ID,
                  Item_Type: "Gift",
                  Item_ID: ThisValue.Item_ID,
                  Trade_Type: 103,
                  Trade_Flag: 1,
                  Trade_Num: ThisValue.Item_Value,
                  Trade_Order_No: parm.Order_No,
                  Remark: "用户抽奖",
                  Create_IP: parm.Create_IP
                }, function (retValue) {
                  callback(retValue.hasError ? retValue : null);
                });
                return;
              case "HORN": //喇叭
                DAL_Factory.Business.User_PackageTransction(_Conn, {
                  User_ID: parm.User_ID,
                  Item_Type: "Horn",
                  Item_ID: ThisValue.Item_ID,
                  Trade_Type: 103,
                  Trade_Flag: 1,
                  Trade_Num: ThisValue.Item_Value,
                  Trade_Order_No: parm.Order_No,
                  Remark: "用户抽奖",
                  Create_IP: parm.Create_IP
                }, function (retValue) {
                  callback(retValue.hasError ? retValue : null);
                });
                return;
              case "VIP": //VIP
                DAL_Factory.User.User_Info.Update_VIP(_Conn, {
                  VIP_Mode: ThisValue.Item_Mode,
                  VIP_Value: ThisValue.Item_Value,
                  User_ID: parm.User_ID
                }, function (retValue) {
                  if (retValue.hasError) {
                    callback(retValue);
                    return;
                  }
                  if (retValue.returnObject !== 1) {
                    retValue.hasError = true;
                    retValue.message = "抽奖VIP出错(影响" + retValue.returnObject + "行)";
                    callback(retValue);
                    return;
                  }
                  callback();
                });
                return;
              case "MOUNTS": //座骑
                var _MountsInfo = CommonUtils.Commodity.Mounts.fnInfo(ThisValue.Item_ID); //读取座骑信息
                DAL_Factory.User.User_Mounts.Insert(_Conn, {
                  User_ID: parm.User_ID,
                  Mounts_ID: ThisValue.Item_ID,
                  Mounts_Mode: ThisValue.Item_Mode,
                  Mounts_Value: ThisValue.Item_Value,
                  Mounts_Name: _MountsInfo.Name,
                  Create_IP: parm.Create_IP
                }, function (retValue) {
                  callback(retValue.hasError ? retValue : null);
                });
                return;
              default:
                callback(KOC.ReturnValue.New({
                  hasError: true,
                  message: "抽奖配置出错,请与管理员联系(2)"
                }));
                return;
            }
          }, function (retValue) {
            if (retValue) {
              callback(retValue);
              return;
            }
            callback();
          });
        },
        //提交事务
        function (callback) {
          KOC.MysqlHelper.TranCommit(_Conn, function (retValue) {
            _Conn = null;
            if (retValue.hasError) {
              callback(retValue);
              return;
            }
            callback();
          });
        },
        //读取用户个人信息
        function (callback) {
          DAL_Factory.User.User_Info.Info(parm.User_ID, function (retValue) {
            if (retValue.hasError) {
              callback(retValue);
              return;
            }
            if (!retValue.returnObject) {
              retValue.hasError = true;
              retValue.message = "用户不存在";
              callback(retValue);
              return;
            }
            parm.UserInfo = retValue.returnObject;
            callback();
          });
        }
      ], function (retValue) {
        if (retValue) {
          console.log("用户抽奖失败:", retValue, parm);
          KOC.MysqlHelper.TranRollback(_Conn, function () {
            callback(retValue);
          });
          return;
        }
        callback(KOC.ReturnValue.New({
          returnObject: {
            User_ID: parm.User_ID,
            EXP: parm.UserInfo.EXP,
            Coin: parm.UserInfo.Coin,
            Pomelo: parm.UserInfo.Pomelo,
            LotteryInfo: parm.Lottery,
            LotteryWinningList: parm.WinningList
          }
        }));
      });
    },
    //endregion
    //region User_LotteryRank:幸运装盘-获奖榜单
    User_LotteryRank: function (parm, callback) {
      parm = KOC.Lodash.extend({
        Length: null,//获取个数
        Type: null,//获取榜单类型：1-日榜，2-周榜，3-月榜，4-年榜，5=总榜，6-任意时间段榜单
        BetweenTime: null,//开始时间
        AndTime: null//结束时间
      }, parm);
      parm.Length = KOC.StringUtils.ToInt(parm.Length, -1);
      parm.Type = KOC.StringUtils.ToInt(parm.Type, -1);
      if (parm.Length <= 0) {
        callback(KOC.ReturnValue.New({
          hasError: true,
          message: "传入参数错误:Length"
        }));
        return;
      }
      if (!KOC.Lodash.includes([1, 2, 3, 4, 5, 6], parm.Type)) {
        callback(KOC.ReturnValue.New({
          hasError: true,
          message: "传入参数错误:Type"
        }));
        return;
      }

      function formateTime(type) {
        parm.BetweenTime = KOC.Moment().startOf(type).format();
        parm.AndTime = KOC.Moment().endOf(type).format();
      }

      //时间处理
      switch (parm.Type) {
        case 1:
          formateTime('day');
          break;
        case 2:
          formateTime('week');
          break;
        case 3:
          formateTime('month');
          break;
        case 4:
          formateTime('year');
          break;
        case 5:
          parm.BetweenTime = null;
          parm.AndTime = null;
          break;
        case 6:
          if (!parm.BetweenTime || !parm.AndTime) {
            callback(KOC.ReturnValue.New({
              hasError: true,
              message: "传入参数错误:BetweenTime,AndTime"
            }));
            return;
          }
          if (!(/^\d{4}-((0[1-9])|(1[0-2]))$/).test(parm.BetweenTime)) {
            callback(KOC.ReturnValue.New({
              hasError: true,
              message: "时间格式错误:BetweenTime"
            }));
            return;
          }
          if (!(/^\d{4}-((0[1-9])|(1[0-2]))$/).test(parm.AndTime)) {
            callback(KOC.ReturnValue.New({
              hasError: true,
              message: "时间格式错误:AndTime"
            }));
            return;
          }
          parm.BetweenTime = KOC.Moment(new Date(parm.BetweenTime)).startOf('day').format();
          parm.AndTime = KOC.Moment(new Date(parm.AndTime)).endOf('day').format();
          break;
        default:
          callback(KOC.ReturnValue.New({
            hasError: true,
            message: "传入参数错误:Type"
          }));
          return;
      }
      DAL_Factory.User.Order_Lottery.Info_Rank({
        Between_Create_Date: parm.BetweenTime,
        And_Create_Date: parm.AndTime,
        Length: parm.Length
      }, function (retValue) {
        if (retValue.hasError) {
          callback(retValue);
          return;
        }
        callback(KOC.ReturnValue.New({
          returnObject: retValue.returnObject
        }));
      });
    },
    //endregion
    //region User_Channel_SignUp_Pay_Info:渠道注册充值信息数据
    User_Channel_SignUp_Pay_Info: function (parm, callback) {
      parm = KOC.Lodash.extend({
        Channel_ID: null,//渠道ID
        Create_Date_Between: null,
        Create_Date_And: null
      }, parm);
      var ChannelList = [118060101, 118060102, 118060103, 118060104];
      parm.Channel_ID = KOC.StringUtils.ToInt(parm.Channel_ID, -1);
      if (parm.Channel_ID > 0 && !KOC.Lodash.includes(ChannelList, parm.Channel_ID)) {
        callback(KOC.ReturnValue.New({
          hasError: true,
          message: "传入参数错误:Channel_ID"
        }));
        return;
      }
      if (!parm.Create_Date_Between || !parm.Create_Date_And) {
        callback(KOC.ReturnValue.New({
          hasError: true,
          message: "传入参数错误:Create_Date"
        }));
        return;
      }
      parm.Create_Date_Between = KOC.Moment(new Date(parm.Create_Date_Between)).startOf('day')._d;
      parm.Create_Date_And = KOC.Moment(new Date(parm.Create_Date_And)).endOf('day')._d;
      //格式化数据
      parm.List = [];
      if (parm.Channel_ID > 0) {
        var data = {
          Channel_ID: -1,
          User_ID_Count: 0,
          SignUp_Pay: {
            User_ID_Count: 0,
            User_ID_Number: 0,
            SUM_Money: 0,
            SUM_Coin: 0
          },
          Pay: {
            User_ID_Count: 0,
            User_ID_Number: 0,
            SUM_Money: 0,
            SUM_Coin: 0
          }
        };
        data.Channel_ID = parm.Channel_ID;
        parm.List.push(data);
      } else {
        for (var i in ChannelList) {
          var data = {
            Channel_ID: -1,
            User_ID_Count: 0,
            SignUp_Pay: {
              User_ID_Count: 0,
              User_ID_Number: 0,
              SUM_Money: 0,
              SUM_Coin: 0
            },
            Pay: {
              User_ID_Count: 0,
              User_ID_Number: 0,
              SUM_Money: 0,
              SUM_Coin: 0
            }
          };
          data.Channel_ID = ChannelList[i];
          parm.List.push(data);
        }
      }
      KOC.Async.series([
        //获取渠道注册人数
        function (callback) {
          DAL_Factory.User.User_Info.Info_SignUp_Channel({
            Create_Date_Between: parm.Create_Date_Between,
            Create_Date_And: parm.Create_Date_And,
            Channel_ID: parm.Channel_ID
          }, function (retValue) {
            if (retValue.hasError) {
              callback(retValue);
              return;
            }
            parm.User_ID_Count_Total = 0;//总注册人数
            if (retValue.returnObject && retValue.returnObject.length > 0) {
              for (var index in retValue.returnObject) {
                for (var channel_id in parm.List) {
                  if (retValue.returnObject[index].Channel_ID == parm.List[channel_id].Channel_ID) {
                    parm.List[channel_id].User_ID_Count = retValue.returnObject[index].User_ID_Count;
                    parm.User_ID_Count_Total += retValue.returnObject[index].User_ID_Count;
                  }
                }
              }
            }
            callback();
          });
        },
        //获取渠道注册并充值人数
        function (callback) {
          DAL_Factory.User.User_Info.Info_SignUp_Pay({
            Create_Date_Between: parm.Create_Date_Between,
            Create_Date_And: parm.Create_Date_And,
            Channel_ID: parm.Channel_ID
          }, function (retValue) {
            if (retValue.hasError) {
              callback(retValue);
              return;
            }
            if (retValue.returnObject && retValue.returnObject.length > 0) {
              for (var index in retValue.returnObject) {
                for (var channel_id in parm.List) {
                  if (retValue.returnObject[index].Channel_ID == parm.List[channel_id].Channel_ID) {
                    parm.List[channel_id].SignUp_Pay = {
                      User_ID_Count: retValue.returnObject[index].User_ID_Count,
                      User_ID_Number: retValue.returnObject[index].User_ID_Number,
                      SUM_Money: retValue.returnObject[index].SUM_Money,
                      SUM_Coin: retValue.returnObject[index].SUM_Coin
                    };
                  }
                }
              }
            }
            callback();
          });
        },
        //获取渠道总充值人数
        function (callback) {
          DAL_Factory.User.Order_Pay.Info_Channel_Pay({
            Create_Date_Between: parm.Create_Date_Between,
            Create_Date_And: parm.Create_Date_And,
            Channel_ID: parm.Channel_ID
          }, function (retValue) {
            if (retValue.hasError) {
              callback(retValue);
              return;
            }
            parm.SUM_Money_Total = 0;//总充值金额
            if (retValue.returnObject && retValue.returnObject.length > 0) {
              for (var index in retValue.returnObject) {
                for (var channel_id in parm.List) {
                  if (retValue.returnObject[index].Channel_ID == parm.List[channel_id].Channel_ID) {
                    parm.List[channel_id].Pay = {
                      User_ID_Count: retValue.returnObject[index].User_ID_Count,
                      User_ID_Number: retValue.returnObject[index].User_ID_Number,
                      SUM_Money: retValue.returnObject[index].SUM_Money,
                      SUM_Coin: retValue.returnObject[index].SUM_Coin
                    };
                    parm.SUM_Money_Total += retValue.returnObject[index].SUM_Money;
                  }
                }
              }
            }
            callback();
          });
        }
      ], function (retValue) {
        if (retValue) {
          callback(retValue);
          return;
        }
        retValue = KOC.ReturnValue.New();
        retValue.returnObject = {
          User_ID_Count_Total: parm.User_ID_Count_Total,
          SUM_Money_Total: parm.SUM_Money_Total,
          List: parm.List
        };
        callback(retValue);
      });
    },
    //endregion
    //region User_WeekStarGrantEmblem:周星榜发放徽章
    User_WeekStarGrantEmblem: function (callback) {
      var parm = {};
      //获取周星信息
      parm.GiftList = CommonUtils.Commodity.Gift.Data;//礼物列表
      parm.WeekStart_GiftList = [];//周星礼物ID列表
      parm.WeekStart_GiftList_Formate = [];//格式化之后的周星礼物列表
      //从配置表中获得周星礼物信息
      for (var index in parm.GiftList) {
        if (parm.GiftList[index].IsWeekStar && parm.GiftList[index].Status == 0) {
          parm.WeekStart_GiftList.push(parm.GiftList[index].id);
        }
      }
      //将周兴礼物信息格式化成统一结构
      for (var gift_key in parm.WeekStart_GiftList) {
        parm.WeekStart_GiftList_Formate.push({
          Gift_ID: parm.WeekStart_GiftList[gift_key],
          Type: 1
        });
        parm.WeekStart_GiftList_Formate.push({
          Gift_ID: parm.WeekStart_GiftList[gift_key],
          Type: 2
        });
      }
      KOC.Async.series([
        //获取艺人榜首信息
        function (callback) {
          parm.WeekStarList = [];//艺人、用户榜首信息
          var userList = [];//榜首用户列表,为了判断用户获得了几个周星榜榜首
          var userWeekStar = [];//周星榜用户列表
          KOC.Async.each(parm.WeekStart_GiftList_Formate, function (ThisValue, callback) {
            DAL_Factory.Business.User_WeekStarRank({
              Gift_ID: ThisValue.Gift_ID,//礼物ID
              Length: 1,//请求个数
              Type: ThisValue.Type,//请求类型：1-艺人周星榜，2-粉丝周星榜
              Week: 2 //请求类型：1-本周， 2-上周, 3-大上周， 4-大大上周， 5-特殊日期
            }, function (retValue) {
              if (retValue.hasError) {
                callback(retValue);
                return;
              }
              //获取榜首信息
              if (retValue.returnObject && retValue.returnObject.Rank && retValue.returnObject.Rank.length > 0) {
                if (retValue.returnObject.Type == 1) {
                  retValue.returnObject.Rank[0].Type = 1;//设置周星榜的类型1-艺人周星榜，2-粉丝周星榜
                  parm.WeekStarList.push(retValue.returnObject.Rank[0]);
                } else {
                  retValue.returnObject.Rank[0].Type = 2;//设置周星榜的类型1-艺人周星榜，2-粉丝周星榜
                  if (KOC.Lodash.includes(userList, retValue.returnObject.Rank[0].User_ID)) {
                    userWeekStar[retValue.returnObject.Rank[0].User_ID].RankNumber++;
                  } else {
                    retValue.returnObject.Rank[0].RankNumber = 1;//获得榜首的次数
                    userList.push(retValue.returnObject.Rank[0].User_ID);
                    userWeekStar[retValue.returnObject.Rank[0].User_ID] = retValue.returnObject.Rank[0];
                  }
                }
              }
              callback();
            });
          }, function (retValue) {
            if (retValue) {
              callback(retValue);
              return;
            }
            //格式化用户周星榜列表(userWeekStar中数据为哈希存储结构，转化为parm.UserWeekStarList数组存储)
            if (userWeekStar && userWeekStar.length > 0) {
              for (var index in userWeekStar) {
                if (userWeekStar[index]) {
                  parm.WeekStarList.push(userWeekStar[index]);
                }
              }
            }
            callback();
          });
        },
        //获得周星奖励徽章
        function (callback) {
          KOC.Async.each(parm.WeekStarList, function (ThisValue, callback) {
            var Emble_Info = null;//徽章信息
            if (ThisValue.Type == 1) {
              Emble_Info = CommonUtils.Commodity.Emblem.fnInfoGiftID(ThisValue.Gift_ID);
            } else {
              Emble_Info = CommonUtils.Commodity.Emblem.fnInfoNumber(ThisValue.RankNumber);
            }
            if (!Emble_Info) {
              callback();
            } else {
              DAL_Factory.Business.User_EmblemGet({
                User_ID: ThisValue.User_ID,
                Duration: 7,
                Item_ID: Emble_Info.ID,
                Create_IP: ""
              }, function (retValue) {
                if (retValue.hasError) {
                  callback(retValue);
                  return;
                }
                callback();
              });
            }
          }, function (retValue) {
            if (retValue) {
              callback(retValue);
              return;
            }
            callback();
          });
        },
        //重置艺人周星榜首信息
        function (callback) {
          DAL_Factory.User.User_Anchor.Update_IsWeekStar({
            IsWeekStar: 0
          }, function (retValue) {
            if (retValue.hasError) {
              callback(retValue);
              return;
            }
            callback();
          });
        },
        //更新新的榜首信息
        function (callback) {
          KOC.Async.each(parm.WeekStarList, function (ThisValue, callback) {
            if (ThisValue.Type == 2) {
              callback();
              return;
            }
            DAL_Factory.User.User_Anchor.Update_IsWeekStar({
              User_ID: ThisValue.User_ID,//艺人ID
              IsWeekStar: 1//周星榜首标记
            }, function (retValue) {
              if (retValue.hasError) {
                callback(retValue);
                return;
              }
              if (retValue.returnObject != 1) {
                retValue.errorCode = 1;
                retValue.message = "更新周星榜首状态信息出错";
                callback(retValue);
                return;
              }
              callback();
            });
          }, function (retValue) {
            if (retValue) {
              callback(retValue);
              return;
            }
            callback();
          });
        }
      ], function (retValue) {
        if (retValue) {
          callback(retValue);
          return;
        }
        callback(KOC.ReturnValue.New());
      });
    },
    //endregion
    //region User_EmblemGet:用户获得徽章
    User_EmblemGet: function (parm, callback) {
      parm = KOC.Lodash.extend({
        User_ID: null,//用户ID
        Duration: null,//时长
        Item_ID: null,//徽章ID
        Create_IP: null
      }, parm);
      parm.User_ID = KOC.StringUtils.ToInt(parm.User_ID, -1);
      parm.Item_ID = KOC.StringUtils.ToInt(parm.Item_ID, -1);
      parm.Duration = KOC.StringUtils.ToInt(parm.Duration, -1);
      if (parm.User_ID <= 0) {
        callback(KOC.ReturnValue.New({
          hasError: true,
          message: "传入参数错误:User_ID"
        }));
        return;
      }
      if (parm.Item_ID <= 0) {
        callback(KOC.ReturnValue.New({
          hasError: true,
          message: "传入参数错误:Item_ID"
        }));
        return;
      }
      if (parm.Duration <= 0) {
        callback(KOC.ReturnValue.New({
          hasError: true,
          message: "传入参数错误:Duration"
        }));
        return;
      }
      KOC.Async.series([
        //读取用户个人信息
        function (callback) {
          DAL_Factory.User.User_Info.Info(parm.User_ID, function (retValue) {
            if (retValue.hasError) {
              callback(retValue);
              return;
            }
            if (!retValue.returnObject) {
              retValue.hasError = true;
              retValue.message = "用户不存在";
              callback(retValue);
              return;
            }
            callback();
          });
        },
        //插入用户徽章表
        function (callback) {
          var Item = CommonUtils.Commodity.Emblem.fnInfo(parm.Item_ID);
          if (!Item) {
            callback(KOC.ReturnValue.New({
              hasError: true,
              message: "徽章配置信息不存在"
            }));
            return;
          }
          if (Item.Status != 0) {
            callback(KOC.ReturnValue.New({
              hasError: true,
              message: "徽章配置信息错误，徽章已锁定"
            }));
            return;
          }
          DAL_Factory.User.User_Emblem.Insert(null, {
            User_ID: parm.User_ID,
            Item_ID: Item.ID,
            Item_Mode: Item.Mode,
            Item_Value: parm.Duration,
            Item_Name: Item.Name,
            Item_Type: Item.Type,
            Create_IP: parm.Create_IP
          }, function (retValue) {
            if (retValue.hasError) {
              callback(retValue);
              return;
            }
            callback();
          });
        }
      ], function (retValue) {
        if (retValue) {
          callback(retValue);
          return;
        }
        retValue = KOC.ReturnValue.New();
        retValue.returnObject = parm;
        callback(retValue);
      });
    },
    //endregion
    //region User_PoundEgg:砸蛋游戏
    User_PoundEgg: function (parm, callback) {
      parm = KOC.Lodash.extend({
        User_ID: null,//用户ID
        User_ID_Anchor: null,//直播间ID
        PoundEgg_ID: null,//砸蛋ID
        Create_IP: null
      }, parm);
      parm.User_ID = KOC.StringUtils.ToInt(parm.User_ID, -1);
      parm.User_ID_Anchor = KOC.StringUtils.ToInt(parm.User_ID_Anchor, -1);
      parm.PoundEgg_ID = KOC.StringUtils.ToInt(parm.PoundEgg_ID, -1);
      //获取抽奖配置信息
      parm.PoundEgg = CommonUtils.PoundEgg.fnInfo(parm.PoundEgg_ID);
      if (parm.User_ID <= 0) {
        callback(KOC.ReturnValue.New({
          hasError: true,
          message: "传入参数错误:User_ID"
        }));
        return;
      }
      if (parm.User_ID_Anchor <= 0) {
        callback(KOC.ReturnValue.New({
          hasError: true,
          message: "传入参数错误:User_ID_Anchor"
        }));
        return;
      }
      if (parm.PoundEgg_ID <= 0) {
        callback(KOC.ReturnValue.New({
          hasError: true,
          message: "传入参数错误:PoundEgg_ID"
        }));
        return;
      }
      if (!parm.PoundEgg || parm.PoundEgg.Status != 0) {
        callback(KOC.ReturnValue.New({
          hasError: true,
          message: "抽奖的配置信息出错,请联系管理员"
        }));
        return;
      }
      var _Conn = null;
      KOC.Async.series([
        //读取用户个人信息
        function (callback) {
          DAL_Factory.User.User_Info.Info(parm.User_ID, function (retValue) {
            if (retValue.hasError) {
              callback(retValue);
              return;
            }
            if (!retValue.returnObject) {
              retValue.hasError = true;
              retValue.message = "用户不存在";
              callback(retValue);
              return;
            }
            if (retValue.returnObject.Coin < parm.PoundEgg.Price) {
              retValue.hasError = true;
              retValue.errorCode = -2;
              retValue.message = "金币不足,请及时充值";
              callback(retValue);
              return;
            }
            parm.User_NickName = retValue.returnObject.NickName;
            parm.User_RealName = retValue.returnObject.RealName;
            callback();
          });
        },
        //读取艺人信息
        function (callback) {
          DAL_Factory.User.User_Anchor.Info(parm.User_ID_Anchor, function (retValue) {
            if (retValue.hasError) {
              callback(retValue);
              return;
            }
            if (!retValue.returnObject) {
              retValue.hasError = true;
              retValue.message = "无此艺人信息";
              callback(retValue);
              return;
            }
            parm.Family_ID = retValue.returnObject.Family_ID ? retValue.returnObject.Family_ID : -1;
            callback();
          });
        },
        //读取艺人公会信息
        function (callback) {
          if (!parm.Family_ID || parm.Family_ID < 0) {
            parm.Family_Name = "";
            callback();
            return;
          }
          DAL_Factory.User.Family_Info.Info(parm.Family_ID, function (retValue) {
            if (retValue.hasError) {
              callback(retValue);
              return;
            }
            if (!retValue.returnObject) {
              retValue.hasError = true;
              retValue.message = "无此公会信息";
              callback(retValue);
              return;
            }
            parm.Family_Name = retValue.returnObject.Family_Name;
            callback();
          });
        },
        //生成单据号
        function (callback) {
          DAL_Factory.Common.Order_No_Manage.Info(CommonUtils.OrderNo.PoundEgg.ID, function (retValue) {
            if (retValue.hasError) {
              callback(retValue);
              return;
            }
            if (!retValue.returnObject || !retValue.returnObject[0].Order_No) {
              retValue.hasError = true;
              retValue.message = "无此单据类型";
              callback(retValue);
              return;
            }
            parm.Order_No = retValue.returnObject[0].Order_No;
            callback();
          });
        },
        //开启事物
        function (callback) {
          KOC.MysqlHelper.TranOpen(Config.Mysql.DB.User, function (retValue) {
            if (retValue.hasError) {
              callback(retValue);
              return;
            }
            _Conn = retValue.returnObject;
            callback();
          });
        },
        //写入用户资金交易记录（扣除抽奖金币）
        function (callback) {
          DAL_Factory.Business.User_BankTransction(_Conn, {
            User_ID: parm.User_ID,
            Related_User_ID: -1,
            Related_User_NickName: "",
            Related_User_RealName: "",
            Related_Family_ID: -1,
            Related_Family_Name: "",
            Trade_Currency: 1,
            Trade_Type: 308,
            Trade_Flag: -1,//扣除用户金币
            Trade_Amt: parm.PoundEgg.Price,
            Trade_Order_No: parm.Order_No,
            Remark: "用户砸蛋-花费金币",
            Create_IP: parm.Create_IP
          }, function (retValue) {
            if (retValue.hasError) {
              callback(retValue);
              return;
            }
            callback();
          });
        },
        //写入抽奖单据表
        function (callback) {
          DAL_Factory.User.Order_PoundEgg.Insert(_Conn, {
            Order_No: parm.Order_No, //单据号
            User_ID: parm.User_ID, //用户ID
            User_NickName: parm.User_NickName, //用户昵称
            User_RealName: parm.User_RealName, //用户真实姓名
            User_ID_Anchor: parm.User_ID_Anchor, //用户ID(艺人，房间)
            Family_ID: parm.Family_ID, //公会ID
            Family_Name: parm.Family_Name, //公会名称
            Order_Amt: parm.PoundEgg.Price, //抽奖金额(金币)
            Count: parm.PoundEgg.Count, //抽奖次数
            Category: parm.PoundEgg.Category, //抽奖类别
            Create_IP: parm.Create_IP //IP地址
          }, function (retValue) {
            if (retValue.hasError) {
              callback(retValue);
              return;
            }
            callback();
          });
        },
        //进行抽奖
        function (callback) {
          DAL_Factory.User.Order_PoundEgg.Update_Proc(_Conn, parm.Order_No, function (retValue) {
            if (retValue.hasError) {
              callback(retValue);
              return;
            }
            if (!retValue.returnObject || retValue.returnObject.length <= 0) {
              retValue.hasError = true;
              retValue.message = "抽奖过程错误";
              callback(retValue);
              return;
            }
            parm.WinningList = retValue.returnObject;
            callback();
          });
        },
        //按照中奖类型进行奖励发放
        function (callback) {
          KOC.Async.each(parm.WinningList, function (ThisValue, callback) {
            switch (ThisValue.Item_Type) {
              case "COIN": //金币
                DAL_Factory.Business.User_BankTransction(_Conn, {
                  User_ID: parm.User_ID,
                  Related_User_ID: -1,
                  Related_User_NickName: "",
                  Related_User_RealName: "",
                  Related_Family_ID: -1,
                  Related_Family_Name: "",
                  Trade_Currency: 1,
                  Trade_Type: 108,
                  Trade_Flag: 1,
                  Trade_Amt: ThisValue.Item_Value,
                  Trade_Order_No: parm.Order_No,
                  Remark: "用户抽奖-获得金币",
                  Create_IP: parm.Create_IP
                }, function (retValue) {
                  callback(retValue.hasError ? retValue : null);
                });
                return;
              case "EXP": //经验
                DAL_Factory.User.User_Info.Update_EXP(_Conn, {
                  EXP: ThisValue.Item_Value,
                  User_ID: parm.User_ID
                }, function (retValue) {
                  if (retValue.hasError) {
                    callback(retValue);
                    return;
                  }
                  if (retValue.returnObject !== 1) {
                    retValue.hasError = true;
                    retValue.message = "抽奖验奖励出错(影响" + retValue.returnObject + "行)";
                    callback(retValue);
                    return;
                  }
                  callback();
                });
                return;
              case "POMELO": //星星
                DAL_Factory.User.User_Info.Update_Pomelo(_Conn, parm.User_ID, ThisValue.Item_Value, function (retValue) {
                  if (retValue.hasError) {
                    callback(retValue);
                    return;
                  }
                  if (retValue.returnObject !== 1) {
                    retValue.hasError = true;
                    retValue.message = "抽奖星星出错(影响" + retValue.returnObject + "行)";
                    callback(retValue);
                    return;
                  }
                  callback();
                });
                return;
              case "GIFT": //礼物
                DAL_Factory.Business.User_PackageTransction(_Conn, {
                  User_ID: parm.User_ID,
                  Item_Type: "Gift",
                  Item_ID: ThisValue.Item_ID,
                  Trade_Type: 103,
                  Trade_Flag: 1,
                  Trade_Num: ThisValue.Item_Value,
                  Trade_Order_No: parm.Order_No,
                  Remark: "用户抽奖",
                  Create_IP: parm.Create_IP
                }, function (retValue) {
                  callback(retValue.hasError ? retValue : null);
                });
                return;
              case "HORN": //喇叭
                DAL_Factory.Business.User_PackageTransction(_Conn, {
                  User_ID: parm.User_ID,
                  Item_Type: "Horn",
                  Item_ID: ThisValue.Item_ID,
                  Trade_Type: 103,
                  Trade_Flag: 1,
                  Trade_Num: ThisValue.Item_Value,
                  Trade_Order_No: parm.Order_No,
                  Remark: "用户抽奖",
                  Create_IP: parm.Create_IP
                }, function (retValue) {
                  callback(retValue.hasError ? retValue : null);
                });
                return;
              case "VIP": //VIP
                DAL_Factory.User.User_Info.Update_VIP(_Conn, {
                  VIP_Mode: ThisValue.Item_Mode,
                  VIP_Value: ThisValue.Item_Value,
                  User_ID: parm.User_ID
                }, function (retValue) {
                  if (retValue.hasError) {
                    callback(retValue);
                    return;
                  }
                  if (retValue.returnObject !== 1) {
                    retValue.hasError = true;
                    retValue.message = "抽奖VIP出错(影响" + retValue.returnObject + "行)";
                    callback(retValue);
                    return;
                  }
                  callback();
                });
                return;
              case "MOUNTS": //座骑
                var _MountsInfo = CommonUtils.Commodity.Mounts.fnInfo(ThisValue.Item_ID); //读取座骑信息
                DAL_Factory.User.User_Mounts.Insert(_Conn, {
                  User_ID: parm.User_ID,
                  Mounts_ID: ThisValue.Item_ID,
                  Mounts_Mode: ThisValue.Item_Mode,
                  Mounts_Value: ThisValue.Item_Value,
                  Mounts_Name: _MountsInfo.Name,
                  Create_IP: parm.Create_IP
                }, function (retValue) {
                  callback(retValue.hasError ? retValue : null);
                });
                return;
              default:
                callback(KOC.ReturnValue.New({
                  hasError: true,
                  message: "抽奖配置出错,请与管理员联系(2)"
                }));
                return;
            }
          }, function (retValue) {
            if (retValue) {
              callback(retValue);
              return;
            }
            callback();
          });
        },
        //提交事务
        function (callback) {
          KOC.MysqlHelper.TranCommit(_Conn, function (retValue) {
            _Conn = null;
            if (retValue.hasError) {
              callback(retValue);
              return;
            }
            callback();
          });
        },
        //读取用户个人信息
        function (callback) {
          DAL_Factory.User.User_Info.Info(parm.User_ID, function (retValue) {
            if (retValue.hasError) {
              callback(retValue);
              return;
            }
            if (!retValue.returnObject) {
              retValue.hasError = true;
              retValue.message = "用户不存在";
              callback(retValue);
              return;
            }
            parm.UserInfo = retValue.returnObject;
            callback();
          });
        }
      ], function (retValue) {
        if (retValue) {
          console.log("用户砸蛋失败:", retValue, parm);
          KOC.MysqlHelper.TranRollback(_Conn, function () {
            callback(retValue);
          });
          return;
        }
        callback(KOC.ReturnValue.New({
          returnObject: {
            User_ID: parm.User_ID,
            EXP: parm.UserInfo.EXP,
            Coin: parm.UserInfo.Coin,
            Pomelo: parm.UserInfo.Pomelo,
            PoundEggInfo: parm.PoundEgg,
            PoundEggWinningList: parm.WinningList
          }
        }));
      });
    },
    //endregion
    //endregion
    //region DB.Report
    //region Report_ChannelStrategy:渠道策略分配
    Report_ChannelStrategy: function (parm, callback) {
      parm = KOC.Lodash.extend({
        Channel_ID: null, //渠道ID
        Room_ID: null, //进入直播间ID
        UV: null, //用户标识
        IP: null //IP
      }, parm);
      parm.Room_ID = KOC.StringUtils.ToIntPositive(parm.Room_ID);
      parm.ChannelStrategy = CommonUtils.ChannelStrategy[parm.Channel_ID] || CommonUtils.ChannelStrategy.Default;
      parm.URLParm = {};
      parm.List = null;
      parm.Specific_List = null;
      parm.Specific_Ratio = 0;
      parm.Recommend_List = null;
      parm.Recommend_Ratio = 0;
      parm.RatingS_List = null;
      parm.RatingS_Ratio = 0;
      parm.RatingA_List = null;
      parm.RatingA_Ratio = 0;
      parm.RatingB_List = null;
      parm.RatingB_Ratio = 0;
      parm.WeekStar_List = null;
      parm.WeekStar_Ratio = 0;
      parm.HotPrevious_List = null;
      parm.HotPrevious_Ratio = 0;
      parm.Hot_List = null;
      parm.Hot_Ratio = 0;
      parm.New_List = null;
      parm.New_Ratio = 0;
      parm.Live_List = null;
      parm.Live_Ratio = 0;
      parm.Target_Random = 0;
      parm.Target_Type = null;
      parm.Target_UserInfo = null;
      parm.Target_URL = null;
      parm.Target_List = null;
      parm.UV_Insert = false;
      parm.IP_Insert = false;
      KOC.Async.series([
        //写入UV(Redis)
        function (callback) {
          DAL_Factory.RedisCommon.ChannelUVListDay.Add(parm.UV, function (retValue) {
            if (retValue.hasError) {
              callback(retValue);
              return;
            }
            parm.UV_Insert = retValue.returnObject == 1;
            callback();
          });
        },
        //写入IP(Redis)
        function (callback) {
          DAL_Factory.RedisCommon.ChannelIPListDay.Add(parm.IP, function (retValue) {
            if (retValue.hasError) {
              callback(retValue);
              return;
            }
            parm.IP_Insert = retValue.returnObject == 1;
            callback();
          });
        },
        //写入渠道日报表
        function (callback) {
          DAL_Factory.Report.Channel_Day.Update({
            Channel_ID: parm.Channel_ID,
            PV: 1,
            UV: parm.UV_Insert ? 1 : 0,
            IP: parm.IP_Insert ? 1 : 0
          }, function (retValue) {
            if (retValue.hasError) {
              callback(retValue);
              return;
            }
            callback();
          });
        },
        //读取指定艺人信息
        function (callback) {
          if (!parm.Room_ID) {
            callback();
            return;
          }
          DAL_Factory.User.User_Anchor.Info(parm.Room_ID, function (retValue) {
            if (retValue.hasError) {
              callback(retValue);
              return;
            }
            if (retValue.returnObject && retValue.returnObject.Live && retValue.returnObject.Live_Stream_Status) {
              parm.Target_UserInfo = retValue.returnObject;
              parm.Target_Type = "RoomID";
              parm.Target_URL = "/room/" + parm.Target_UserInfo.User_ID;
            }
            callback();
          });
        },
        //读取艺人数据(渠道策略)
        function (callback) {
          if (parm.Target_UserInfo) {
            callback();
            return;
          }
          DAL_Factory.User.User_Anchor.List_ChannelStrategy(function (retValue) {
            if (retValue.hasError) {
              callback(retValue);
              return;
            }
            parm.List = retValue.returnObject;
            callback();
          });
        },
        //Specific
        function (callback) {
          if (parm.Target_UserInfo) {
            callback();
            return;
          }
          parm.Specific_Ratio = parm.ChannelStrategy.Specific ? KOC.StringUtils.ToIntPositive(parm.ChannelStrategy.Specific.Ratio) : 0;
          if (!parm.Specific_Ratio) {
            callback();
            return;
          }
          DAL_Factory.User.User_Anchor.List_ChannelStrategySpecific(parm.ChannelStrategy.Specific.List, function (retValue) {
            if (retValue.hasError) {
              callback(retValue);
              return;
            }
            parm.Specific_List = retValue.returnObject;
            if (parm.Specific_List.length <= 0) {
              parm.Specific_Ratio = 0;
              callback();
              return;
            }
            if (parm.ChannelStrategy.Specific.SingleMAX && parm.Specific_Ratio > parm.ChannelStrategy.Specific.SingleMAX * parm.Specific_List.length) {
              parm.Specific_Ratio = parm.ChannelStrategy.Specific.SingleMAX * parm.Specific_List.length;
            }
            callback();
          });
        },
        //Recommend
        function (callback) {
          if (parm.Target_UserInfo) {
            callback();
            return;
          }
          parm.Recommend_Ratio = parm.ChannelStrategy.Recommend ? KOC.StringUtils.ToIntPositive(parm.ChannelStrategy.Recommend.Ratio) : 0;
          if (!parm.Recommend_Ratio) {
            callback();
            return;
          }
          parm.Recommend_List = KOC.Lodash.filter(parm.List, {Type: "Recommend"});
          if (parm.Recommend_List.length <= 0) {
            parm.Recommend_Ratio = 0;
            callback();
            return;
          }
          if (parm.ChannelStrategy.Recommend.SingleMAX && parm.Recommend_Ratio > parm.ChannelStrategy.Recommend.SingleMAX * parm.Recommend_List.length) {
            parm.Recommend_Ratio = parm.ChannelStrategy.Recommend.SingleMAX * parm.Recommend_List.length;
          }
          callback();
        },
        //RatingS
        function (callback) {
          if (parm.Target_UserInfo) {
            callback();
            return;
          }
          parm.RatingS_Ratio = parm.ChannelStrategy.RatingS ? KOC.StringUtils.ToIntPositive(parm.ChannelStrategy.RatingS.Ratio) : 0;
          if (!parm.RatingS_Ratio) {
            callback();
            return;
          }
          parm.RatingS_List = KOC.Lodash.filter(parm.List, {Type: "RatingS"});
          if (parm.RatingS_List.length <= 0) {
            parm.RatingS_Ratio = 0;
            callback();
            return;
          }
          if (parm.ChannelStrategy.RatingS.SingleMAX && parm.RatingS_Ratio > parm.ChannelStrategy.RatingS.SingleMAX * parm.RatingS_List.length) {
            parm.RatingS_Ratio = parm.ChannelStrategy.RatingS.SingleMAX * parm.RatingS_List.length;
          }
          callback();
        },
        //RatingA
        function (callback) {
          if (parm.Target_UserInfo) {
            callback();
            return;
          }
          parm.RatingA_Ratio = parm.ChannelStrategy.RatingA ? KOC.StringUtils.ToIntPositive(parm.ChannelStrategy.RatingA.Ratio) : 0;
          if (!parm.RatingA_Ratio) {
            callback();
            return;
          }
          parm.RatingA_List = KOC.Lodash.filter(parm.List, {Type: "RatingA"});
          if (parm.RatingA_List.length <= 0) {
            parm.RatingA_Ratio = 0;
            callback();
            return;
          }
          if (parm.ChannelStrategy.RatingA.SingleMAX && parm.RatingA_Ratio > parm.ChannelStrategy.RatingA.SingleMAX * parm.RatingA_List.length) {
            parm.RatingA_Ratio = parm.ChannelStrategy.RatingA.SingleMAX * parm.RatingA_List.length;
          }
          callback();
        },
        //RatingB
        function (callback) {
          if (parm.Target_UserInfo) {
            callback();
            return;
          }
          parm.RatingB_Ratio = parm.ChannelStrategy.RatingB ? KOC.StringUtils.ToIntPositive(parm.ChannelStrategy.RatingB.Ratio) : 0;
          if (!parm.RatingB_Ratio) {
            callback();
            return;
          }
          parm.RatingB_List = KOC.Lodash.filter(parm.List, {Type: "RatingB"});
          if (parm.RatingB_List.length <= 0) {
            parm.RatingB_Ratio = 0;
            callback();
            return;
          }
          if (parm.ChannelStrategy.RatingB.SingleMAX && parm.RatingB_Ratio > parm.ChannelStrategy.RatingB.SingleMAX * parm.RatingB_List.length) {
            parm.RatingB_Ratio = parm.ChannelStrategy.RatingB.SingleMAX * parm.RatingB_List.length;
          }
          callback();
        },
        //WeekStar
        function (callback) {
          if (parm.Target_UserInfo) {
            callback();
            return;
          }
          parm.WeekStar_Ratio = parm.ChannelStrategy.WeekStar ? KOC.StringUtils.ToIntPositive(parm.ChannelStrategy.WeekStar.Ratio) : 0;
          if (!parm.WeekStar_Ratio) {
            callback();
            return;
          }
          parm.WeekStar_List = KOC.Lodash.filter(parm.List, {Type: "WeekStar"});
          if (parm.WeekStar_List.length <= 0) {
            parm.WeekStar_Ratio = 0;
            callback();
            return;
          }
          if (parm.ChannelStrategy.WeekStar.SingleMAX && parm.WeekStar_Ratio > parm.ChannelStrategy.WeekStar.SingleMAX * parm.WeekStar_List.length) {
            parm.WeekStar_Ratio = parm.ChannelStrategy.WeekStar.SingleMAX * parm.WeekStar_List.length;
          }
          callback();
        },
        //HotPrevious
        function (callback) {
          if (parm.Target_UserInfo) {
            callback();
            return;
          }
          parm.HotPrevious_Ratio = parm.ChannelStrategy.HotPrevious ? KOC.StringUtils.ToIntPositive(parm.ChannelStrategy.HotPrevious.Ratio) : 0;
          if (!parm.HotPrevious_Ratio) {
            callback();
            return;
          }
          parm.HotPrevious_List = KOC.Lodash.filter(parm.List, {Type: "HotPrevious"});
          if (parm.HotPrevious_List.length <= 0) {
            parm.HotPrevious_Ratio = 0;
            callback();
            return;
          }
          if (parm.ChannelStrategy.HotPrevious.Limit && parm.ChannelStrategy.HotPrevious.Limit > 0 && parm.ChannelStrategy.HotPrevious.Limit < parm.HotPrevious_List.length) {
            parm.HotPrevious_List = KOC.Lodash.take(parm.HotPrevious_List, parm.ChannelStrategy.HotPrevious.Limit);
          }
          if (parm.ChannelStrategy.HotPrevious.SingleMAX && parm.HotPrevious_Ratio > parm.ChannelStrategy.HotPrevious.SingleMAX * parm.HotPrevious_List.length) {
            parm.HotPrevious_Ratio = parm.ChannelStrategy.HotPrevious.SingleMAX * parm.HotPrevious_List.length;
          }
          callback();
        },
        //Hot
        function (callback) {
          if (parm.Target_UserInfo) {
            callback();
            return;
          }
          parm.Hot_Ratio = parm.ChannelStrategy.Hot ? KOC.StringUtils.ToIntPositive(parm.ChannelStrategy.Hot.Ratio) : 0;
          if (!parm.Hot_Ratio) {
            callback();
            return;
          }
          parm.Hot_List = KOC.Lodash.filter(parm.List, {Type: "Hot"});
          if (parm.Hot_List.length <= 0) {
            parm.Hot_Ratio = 0;
            callback();
            return;
          }
          if (parm.ChannelStrategy.Hot.Limit && parm.ChannelStrategy.Hot.Limit > 0 && parm.ChannelStrategy.Hot.Limit < parm.Hot_List.length) {
            parm.Hot_List = KOC.Lodash.take(parm.Hot_List, parm.ChannelStrategy.Hot.Limit);
          }
          if (parm.ChannelStrategy.Hot.SingleMAX && parm.Hot_Ratio > parm.ChannelStrategy.Hot.SingleMAX * parm.Hot_List.length) {
            parm.Hot_Ratio = parm.ChannelStrategy.Hot.SingleMAX * parm.Hot_List.length;
          }
          callback();
        },
        //New
        function (callback) {
          if (parm.Target_UserInfo) {
            callback();
            return;
          }
          parm.New_Ratio = parm.ChannelStrategy.New ? KOC.StringUtils.ToIntPositive(parm.ChannelStrategy.New.Ratio) : 0;
          if (!parm.New_Ratio) {
            callback();
            return;
          }
          parm.New_List = KOC.Lodash.filter(parm.List, {Type: "New"});
          if (parm.New_List.length <= 0) {
            parm.New_Ratio = 0;
            callback();
            return;
          }
          if (parm.ChannelStrategy.New.Day && parm.ChannelStrategy.New.Day >= 0) {
            parm.New_List = KOC.Lodash.filter(parm.New_List, function (o) {
              return KOC.StringUtils.ToIntPositive(KOC.Moment().format("YYYYMMDD")) - KOC.StringUtils.ToIntPositive(KOC.Moment(o.Create_Date).format("YYYYMMDD")) <= parm.ChannelStrategy.New.Day;
            });
          }
          if (parm.New_List.length <= 0) {
            parm.New_Ratio = 0;
            callback();
            return;
          }
          if (parm.ChannelStrategy.New.Limit && parm.ChannelStrategy.New.Limit > 0 && parm.ChannelStrategy.New.Limit < parm.New_List.length) {
            parm.New_List = KOC.Lodash.take(parm.New_List, parm.ChannelStrategy.New.Limit);
          }
          if (parm.ChannelStrategy.New.SingleMAX && parm.New_Ratio > parm.ChannelStrategy.New.SingleMAX * parm.New_List.length) {
            parm.New_Ratio = parm.ChannelStrategy.New.SingleMAX * parm.New_List.length;
          }
          callback();
        },
        //Live
        function (callback) {
          if (parm.Target_UserInfo) {
            callback();
            return;
          }
          parm.Live_Ratio = parm.ChannelStrategy.Live ? KOC.StringUtils.ToIntPositive(parm.ChannelStrategy.Live.Ratio) : 0;
          if (!parm.Live_Ratio) {
            callback();
            return;
          }
          parm.Live_List = KOC.Lodash.filter(parm.List, {Type: "Live"});
          if (parm.Live_List.length <= 0) {
            parm.Live_Ratio = 0;
            callback();
            return;
          }
          if (parm.ChannelStrategy.Live.SingleMAX && parm.Live_Ratio > parm.ChannelStrategy.Live.SingleMAX * parm.Live_List.length) {
            parm.Live_Ratio = parm.ChannelStrategy.Live.SingleMAX * parm.Live_List.length;
          }
          callback();
        },
        //计算分配地址
        function (callback) {
          if (parm.Target_UserInfo) {
            callback();
            return;
          }
          parm.Target_Random = parm.Specific_Ratio + parm.Recommend_Ratio + parm.RatingS_Ratio + parm.RatingA_Ratio + parm.RatingB_Ratio + parm.WeekStar_Ratio + parm.HotPrevious_Ratio + parm.Hot_Ratio + parm.New_Ratio + parm.Live_Ratio;
          parm.Target_Random = KOC.Lodash.random(parm.Target_Random > 100 ? parm.Target_Random : 100);
          if (parm.Specific_Ratio > 0 && parm.Target_Random <= parm.Specific_Ratio) {
            parm.Target_Type = "Specific";
            parm.Target_List = parm.Specific_List;
          } else if (parm.Recommend_Ratio > 0 && parm.Target_Random <= parm.Specific_Ratio + parm.Recommend_Ratio) {
            parm.Target_Type = "Recommend";
            parm.Target_List = parm.Recommend_List;
          } else if (parm.RatingS_Ratio > 0 && parm.Target_Random <= parm.Specific_Ratio + parm.Recommend_Ratio + parm.RatingS_Ratio) {
            parm.Target_Type = "Rating";
            parm.Target_List = parm.RatingS_List;
          } else if (parm.RatingA_Ratio > 0 && parm.Target_Random <= parm.Specific_Ratio + parm.Recommend_Ratio + parm.RatingS_Ratio + parm.RatingA_Ratio) {
            parm.Target_Type = "Rating";
            parm.Target_List = parm.RatingA_List;
          } else if (parm.RatingB_Ratio > 0 && parm.Target_Random <= parm.Specific_Ratio + parm.Recommend_Ratio + parm.RatingS_Ratio + parm.RatingA_Ratio + parm.RatingB_Ratio) {
            parm.Target_Type = "Rating";
            parm.Target_List = parm.RatingB_List;
          } else if (parm.WeekStar_Ratio > 0 && parm.Target_Random <= parm.Specific_Ratio + parm.Recommend_Ratio + parm.RatingS_Ratio + parm.RatingA_Ratio + parm.RatingB_Ratio + parm.WeekStar_Ratio) {
            parm.Target_Type = "WeekStar";
            parm.Target_List = parm.WeekStar_List;
          } else if (parm.HotPrevious_Ratio > 0 && parm.Target_Random <= parm.Specific_Ratio + parm.Recommend_Ratio + parm.RatingS_Ratio + parm.RatingA_Ratio + parm.RatingB_Ratio + parm.WeekStar_Ratio + parm.HotPrevious_Ratio) {
            parm.Target_Type = "HotPrevious";
            parm.Target_List = parm.HotPrevious_List;
          } else if (parm.Hot_Ratio > 0 && parm.Target_Random <= parm.Specific_Ratio + parm.Recommend_Ratio + parm.RatingS_Ratio + parm.RatingA_Ratio + parm.RatingB_Ratio + parm.WeekStar_Ratio + parm.HotPrevious_Ratio + parm.Hot_Ratio) {
            parm.Target_Type = "Hot";
            parm.Target_List = parm.Hot_List;
          } else if (parm.New_Ratio > 0 && parm.Target_Random <= parm.Specific_Ratio + parm.Recommend_Ratio + parm.RatingS_Ratio + parm.RatingA_Ratio + parm.RatingB_Ratio + parm.WeekStar_Ratio + parm.HotPrevious_Ratio + parm.Hot_Ratio + parm.New_Ratio) {
            parm.Target_Type = "New";
            parm.Target_List = parm.New_List;
          } else if (parm.Live_Ratio > 0 && parm.Target_Random <= parm.Specific_Ratio + parm.Recommend_Ratio + parm.RatingS_Ratio + parm.RatingA_Ratio + parm.RatingB_Ratio + parm.WeekStar_Ratio + parm.HotPrevious_Ratio + parm.Hot_Ratio + parm.New_Ratio + parm.Live_Ratio) {
            parm.Target_Type = "Live";
            parm.Target_List = parm.Live_List;
          } else {
            parm.Target_Type = "Index";
            parm.Target_URL = "/";
            callback();
            return;
          }
          DAL_Factory.User.User_Anchor.Info(KOC.Lodash.sample(parm.Target_List).User_ID, function (retValue) {
            if (retValue.hasError) {
              callback(retValue);
              return;
            }
            if (!retValue.returnObject) {
              parm.Target_Type += "-NotData";
              parm.Target_URL = "/";
              callback();
              return;
            }
            if (!retValue.returnObject.Live) {
              parm.Target_Type += "-NotLive";
              parm.Target_URL = "/";
              callback();
              return;
            }
            if (!retValue.returnObject.Live_Stream_Status) {
              parm.Target_Type += "-NotLiveStream";
              parm.Target_URL = "/";
              callback();
              return;
            }
            parm.Target_UserInfo = retValue.returnObject;
            parm.Target_URL = "/room/" + parm.Target_UserInfo.User_ID;
            callback();
          });
        },
        //写入分配数据
        function (callback) {
          DAL_Factory.Report.Channel_Strategy_Day.Update({
            Channel_ID: parm.Channel_ID,
            Type: parm.Target_Type,
            User_ID: parm.Target_UserInfo ? parm.Target_UserInfo.User_ID : -1,
            Family_ID: parm.Target_UserInfo ? (parm.Target_UserInfo.Family_ID || -1) : -1
          }, function () {
            callback();
          });
        }
      ], function (retValue) {
        if (retValue) {
          parm.Target_Type = "Index-Error";
          parm.Target_URL = "/";
        } else {
          retValue = KOC.ReturnValue.New();
        }
        if (parm.Channel_ID) {
          parm.URLParm._cid = parm.Channel_ID;
        }
        parm.URLParm._cstype = parm.Target_Type;
        retValue.returnObject = parm.Target_URL + (parm.Target_URL.indexOf("?") == -1 ? "?" : "&") + QueryString.stringify(parm.URLParm);
        callback(retValue);
      });
    },
    //endregion
    //endregion
    //region Redis.Common
    //region RedisCommon_UserAnchorList:用户艺人列表数据(热度值)维护
    RedisCommon_UserAnchorList: function (callback) {
      var parm = {
        HotValuePrevious: [],
        HotValueCurrent: [],
        HotValue: [],
        NewValue: []
      };
      KOC.Async.series([
        //读取头牌
        function (callback) {
          DAL_Factory.User.User_Anchor.List_Hot_J({
            Limit: 1,
            AnchorLive: 1,
            AnchorLiveStreamStatus: 1,
            Order: "HotValuePrevious"
          }, function (retValue) {
            if (retValue.hasError) {
              callback();
              return;
            }
            parm.HotValuePrevious = retValue.returnObject;
            callback();
          });
        },
        //读取艺人热度榜
        function (callback) {
          DAL_Factory.User.User_Anchor.List_Hot_J({
            Limit: 300
          }, function (retValue) {
            if (retValue.hasError) {
              callback();
              return;
            }
            parm.HotValueCurrent = retValue.returnObject;
            callback();
          });
        },
        //Redis热度榜-写入数据
        function (callback) {
          KOC.Lodash.forEach(parm.HotValuePrevious, function (ThisValue) {
            parm.HotValue.push(ThisValue);
          });
          KOC.Lodash.forEach(parm.HotValueCurrent, function (ThisValue, n) {
            if (!KOC.Lodash.find(parm.HotValuePrevious, {User_ID: ThisValue.User_ID})) {
              parm.HotValue.push(ThisValue);
            }
          });
          DAL_Factory.RedisCommon.UserAnchorListHot.Add(parm.HotValue, function (retValue) {
            if (retValue.hasError) {
              callback(retValue);
              return;
            }
            callback();
          });
        },
        //读取艺人新秀榜
        function (callback) {
          DAL_Factory.User.User_Anchor.List_Hot_J({
            Limit: 100,
            Order: "New"
          }, function (retValue) {
            if (retValue.hasError) {
              callback();
              return;
            }
            parm.NewValue = retValue.returnObject;
            callback();
          });
        },
        //Redis新秀榜-写入数据
        function (callback) {
          DAL_Factory.RedisCommon.UserAnchorListNew.Add(parm.NewValue, function (retValue) {
            if (retValue.hasError) {
              callback(retValue);
              return;
            }
            callback();
          });
        }
      ], function (retValue) {
        if (retValue) {
          callback(retValue);
          return;
        }
        callback(KOC.ReturnValue.New());
      });
    },
    //endregion
    //region RedisCommon_GiftUserRankingSet:礼物用户排行榜写入(礼物赠送时)
    RedisCommon_GiftUserRankingSet: function (parm, callback) {
      parm = KOC.Lodash.extend({
        Gift_ID: null,
        User_ID: null,
        User_ID_Gift: null,
        Num: null
      }, parm);
      //写入周榜
      DAL_Factory.RedisCommon.GiftUserRankingWeek.Add(parm, function (retValue) {
        callback(retValue);
      });
    },
    //endregion
    //region RedisCommon_GiftUserRankingWeekReset:礼物用户排行榜同步修正
    RedisCommon_GiftUserRankingWeekReset: function (callback) {
      //取得本周时间
      var _parm = {
        DateStart: KOC.Moment().startOf("week").format("YYYY-MM-DD"),
        DateEnd: KOC.Moment().endOf("week").format("YYYY-MM-DD HH:mm:ss"),
        List: []
      };
      KOC.Async.series([
        //读取数据(送出)(mysql)
        function (callback) {
          DAL_Factory.User.Order_Gift.List_GroupGiftUser({
            GroupType: "G",
            Create_Date_Start: _parm.DateStart,
            Create_Date_End: _parm.DateEnd
          }, function (retValue) {
            if (retValue.hasError) {
              callback(retValue);
              return;
            }
            _parm.List = retValue.returnObject;
            callback();
          });
        },
        //重写数据(送出)
        function (callback) {
          if (_parm.List.length == 0) {
            callback();
            return;
          }
          DAL_Factory.RedisCommon.GiftUserRankingWeek.AddForReset("G", _parm.List, function (retValue) {
            if (retValue.hasError) {
              callback(retValue);
              return;
            }
            callback();
          });
        },
        //读取数据(接收)(mysql)
        function (callback) {
          DAL_Factory.User.Order_Gift.List_GroupGiftUser({
            GroupType: "R",
            Create_Date_Start: _parm.DateStart,
            Create_Date_End: _parm.DateEnd
          }, function (retValue) {
            if (retValue.hasError) {
              callback(retValue);
              return;
            }
            _parm.List = retValue.returnObject;
            callback();
          });
        },
        //重写数据(收到)
        function (callback) {
          if (_parm.List.length == 0) {
            callback();
            return;
          }
          DAL_Factory.RedisCommon.GiftUserRankingWeek.AddForReset("R", _parm.List, function (retValue) {
            if (retValue.hasError) {
              callback(retValue);
              return;
            }
            callback();
          });
        }
      ], function (retValue) {
        if (retValue) {
          callback(retValue);
          return;
        }
        callback(KOC.ReturnValue.New());
      });
    },
    //endregion
    //region RedisCommon_GiftUserRankingWeekList:礼物用户排行榜取得列表
    RedisCommon_GiftUserRankingWeekList: function (parm, callback) {
      parm = KOC.Lodash.extend({
        Gift_ID: null, //WeekStar:所有周星礼物 其它:礼物ID(多个用,号分隔)
        Limit_G: null, //送出人-获取数量 <=0:不获取 >0:取得数量
        Limit_R: null //接收人-获取数量 <=0:不获取 >0:取得数量
      }, parm);
      parm.Limit_G = KOC.StringUtils.ToIntPositive(parm.Limit_G);
      parm.Limit_R = KOC.StringUtils.ToIntPositive(parm.Limit_R);
      if (!parm.Limit_G && !parm.Limit_R) {
        callback(KOC.ReturnValue.New({
          hasError: true,
          message: "参数错误[Limit]"
        }));
      }
      //读取礼物信息
      parm.Gift_List = [];
      if (parm.Gift_ID == "WeekStar") {
        parm.Gift_List = KOC.Lodash.filter(CommonUtils.Commodity.Gift.Data, {IsWeekStar: true, Status: 0});
      } else {
        KOC.Lodash.forEach(String(parm.Gift_ID).split(","), function (ThisValue) {
          ThisValue = CommonUtils.Commodity.Gift.fnInfo(ThisValue);
          if (ThisValue) {
            parm.Gift_List.push(ThisValue);
          }
        });
      }
      if (parm.Gift_List.length == 0) {
        callback(KOC.ReturnValue.New());
        return;
      }
      parm.ValueList = [];
      KOC.Async.each(parm.Gift_List, function (ThisValue, callback) {
        ThisValue = {
          Gift_ID: ThisValue.id,
          Gift_Name: ThisValue.Name,
          Gift_Intro: ThisValue.Intro,
          Gift_Price: ThisValue.Price,
          Gift_IsVIP: ThisValue.IsVIP,
          Gift_IsGuardian: ThisValue.IsGuardian,
          Gift_IsLucky: ThisValue.IsLucky,
          Gift_IsActivity: ThisValue.IsActivity,
          Gift_IsTask: ThisValue.IsTask !== false,
          Gift_IsWeekStar: ThisValue.IsWeekStar,
          Gift_WeekStarMin: ThisValue.WeekStarMin,
          Gift_WeekStarAward: ThisValue.WeekStarAward,
          Ranking_G: [],
          Ranking_R: []
        };
        KOC.Async.series([
          //读取送出人排行
          function (callback) {
            if (!parm.Limit_G) {
              callback();
              return;
            }
            DAL_Factory.RedisCommon.GiftUserRankingWeek.GetList({
              Type: "G",
              Gift_ID: ThisValue.Gift_ID,
              Length: parm.Limit_G
            }, function (retValue) {
              if (retValue.hasError) {
                callback(retValue);
                return;
              }
              ThisValue.Ranking_G = retValue.returnObject;
              callback();
            });
          },
          //读取接收人排行
          function (callback) {
            if (!parm.Limit_R) {
              callback();
              return;
            }
            DAL_Factory.RedisCommon.GiftUserRankingWeek.GetList({
              Type: "R",
              Gift_ID: ThisValue.Gift_ID,
              Length: parm.Limit_R
            }, function (retValue) {
              if (retValue.hasError) {
                callback(retValue);
                return;
              }
              ThisValue.Ranking_R = retValue.returnObject;
              callback();
            });
          },
          //读取用户详细信息
          function (callback) {
            KOC.Async.each([ThisValue.Ranking_G, ThisValue.Ranking_R], function (ThisValue, callback) {
              if (ThisValue.length == 0) {
                callback();
                return;
              }
              KOC.Async.each(ThisValue, function (ThisValue, callback) {
                KOC.Async.series([
                  //读取用户信息
                  function (callback) {
                    DAL_Factory.User.User_Info.Info(ThisValue.User_ID, function (retValue) {
                      if (retValue.hasError) {
                        callback(retValue);
                        return;
                      }
                      if (!retValue.returnObject) {
                        retValue.hasError = true;
                        retValue.message = "没有找到相关用户信息";
                        return;
                      }
                      ThisValue.NickName = retValue.returnObject.NickName;
                      ThisValue.Sex = retValue.returnObject.Sex;
                      ThisValue.Level = retValue.returnObject.Level;
                      ThisValue.Level_Name = retValue.returnObject.Level_Name;
                      ThisValue.Level_Next = retValue.returnObject.Level_Next;
                      ThisValue.Level_Next_Name = retValue.returnObject.Level_Next_Name;
                      ThisValue.EXP = retValue.returnObject.EXP;
                      ThisValue.EXP_Next = retValue.returnObject.EXP_Next;
                      ThisValue.EXP_Difference = retValue.returnObject.EXP_Difference;
                      ThisValue.VIP = retValue.returnObject.VIP;
                      ThisValue.VIP_Expire = retValue.returnObject.VIP_Expire;
                      ThisValue.VIP_ExpireDay = retValue.returnObject.VIP_ExpireDay;
                      ThisValue.IsAnchor = retValue.returnObject.IsAnchor;
                      ThisValue.IsFamily = retValue.returnObject.IsFamily;
                      ThisValue.IsAdmin = retValue.returnObject.IsAdmin;
                      ThisValue.Status = retValue.returnObject.Status;
                      callback();
                    });
                  },
                  //读取艺人信息
                  function (callback) {
                    if (!ThisValue.IsAnchor) {
                      callback();
                      return;
                    }
                    DAL_Factory.User.User_Anchor.Info(ThisValue.User_ID, function (retValue) {
                      if (retValue.hasError) {
                        callback(retValue);
                        return;
                      }
                      if (!retValue.returnObject) {
                        retValue.hasError = true;
                        retValue.message = "没有找到相关用户(艺人)信息";
                        return;
                      }
                      ThisValue.RoomName = retValue.returnObject.RoomName;
                      ThisValue.Live = retValue.returnObject.Live;
                      ThisValue.Live_IsMobile = retValue.returnObject.Live_IsMobile;
                      ThisValue.Live_Mode = retValue.returnObject.Live_Mode;
                      ThisValue.Live_StartTime = retValue.returnObject.Live_StartTime;
                      ThisValue.Live_Stream_Status = retValue.returnObject.Live_Stream_Status;
                      ThisValue.Anchor_Level = retValue.returnObject.Level;
                      ThisValue.Anchor_Level_Name = retValue.returnObject.Level_Name;
                      ThisValue.Anchor_Level_Next = retValue.returnObject.Level_Next;
                      ThisValue.Anchor_Level_Next_Name = retValue.returnObject.Level_Next_Name;
                      ThisValue.Anchor_EXP = retValue.returnObject.EXP;
                      ThisValue.Anchor_EXP_Next = retValue.returnObject.EXP_Next;
                      ThisValue.Anchor_EXP_Difference = retValue.returnObject.EXP_Difference;
                      ThisValue.Anchor_Status = retValue.returnObject.Status;
                      callback();
                    });
                  }
                ], function (retValue) {
                  if (retValue) {
                    callback(retValue);
                    return;
                  }
                  callback();
                });
              }, function (retValue) {
                if (retValue) {
                  callback(retValue);
                  return;
                }
                callback();
              });
            }, function (retValue) {
              if (retValue) {
                callback(retValue);
                return;
              }
              callback();
            });
          }
        ], function (retValue) {
          if (retValue) {
            callback(retValue);
            return;
          }
          parm.ValueList.push(ThisValue);
          callback();
        });
      }, function (retValue) {
        if (retValue) {
          callback(retValue);
          return;
        }
        callback(KOC.ReturnValue.New({
          returnObject: parm.ValueList
        }));
      });
    },
    //endregion
    //endregion
    //region Redis.Room
    //region RedisRoom_RoomUserInfo:取得房间用户信息
    RedisRoom_RoomUserInfo: function (Value, callback) {
      Value = KOC.Lodash.extend({
        RoomID: null,
        User_ID: null,
        Timeout: false,
        TimeoutCurrent: 0
      }, Value);
      Value.TimeoutMAX = 2000;
      var _RoomUserInfo = {
        RoomID: null,
        Guest: true,
        User_ID: null,
        NickName: null,
        Sex: -1,
        Pomelo: 0,
        EXP: 0,
        EXP_Next: 0,
        EXP_Difference: 0,
        Level: 0,
        Level_Name: "",
        Level_Next: 0,
        Level_Next_Name: 0,
        VIP: false,
        VIP_Expire: null,
        Coin: 0,
        Beans: 0,
        IsAnchor: false,
        IsFamily: false,
        IsAdmin: false,
        IsPhone: false,
        RoomAnchor: false,
        RoomAdmin: false,
        RoomGuardian: false,
        RoomGuardian_Mode: "",
        RoomGuardian_Expire: null,
        RoomGuardian_ExpireDay: 0,
        RoomBlack: false,
        RoomBlack_Shutup_Expire: null,
        EmblemList: ""
      };
      KOC.Async.series([
        //读取房间用户信息
        function (callback) {
          DAL_Factory.RedisRoom.Room_UserInfo.Get(Value.RoomID, Value.User_ID, function (retValue) {
            if (retValue.hasError) {
              callback(retValue);
              return;
            }
            _RoomUserInfo.RoomID = retValue.returnObject.RoomID;
            _RoomUserInfo.Guest = retValue.returnObject.Guest;
            _RoomUserInfo.User_ID = retValue.returnObject.User_ID;
            _RoomUserInfo.NickName = retValue.returnObject.NickName;
            _RoomUserInfo.RoomAnchor = retValue.returnObject.Anchor;
            _RoomUserInfo.RoomAdmin = retValue.returnObject.Admin;
            _RoomUserInfo.RoomGuardian = retValue.returnObject.Guardian;
            _RoomUserInfo.RoomGuardian_Mode = retValue.returnObject.Guardian_Mode;
            _RoomUserInfo.RoomGuardian_Expire = retValue.returnObject.Guardian_Expire;
            _RoomUserInfo.RoomGuardian_ExpireDay = retValue.returnObject.Guardian_ExpireDay;
            _RoomUserInfo.RoomBlack = retValue.returnObject.Black;
            _RoomUserInfo.RoomBlack_Shutup_Expire = retValue.returnObject.Black_Shutup_Expire;
            _RoomUserInfo.RoomGiftLast_ID = retValue.returnObject.GiftLast_ID;
            _RoomUserInfo.RoomGiftLast_UserID = retValue.returnObject.GiftLast_UserID;
            _RoomUserInfo.RoomGiftLast_Num = retValue.returnObject.GiftLast_Num;
            _RoomUserInfo.RoomGiftLast_Count = retValue.returnObject.GiftLast_Count;
            _RoomUserInfo.RoomGiftLast_Date = retValue.returnObject.GiftLast_Date;
            _RoomUserInfo.EmblemList = retValue.returnObject.EmblemList;
            callback();
          });
        },
        //读取用户信息
        function (callback) {
          if (_RoomUserInfo.Guest) {
            callback();
            return;
          }
          DAL_Factory.RedisRoom.UserInfo.Get(Value.User_ID, function (retValue) {
            if (retValue.hasError) {
              callback(retValue);
              return;
            }
            _RoomUserInfo.NickName = retValue.returnObject.NickName;
            _RoomUserInfo.Sex = retValue.returnObject.Sex;
            _RoomUserInfo.Pomelo = retValue.returnObject.Pomelo;
            _RoomUserInfo.EXP = retValue.returnObject.EXP;
            _RoomUserInfo.EXP_Next = retValue.returnObject.EXP_Next;
            _RoomUserInfo.EXP_Difference = retValue.returnObject.EXP_Difference;
            _RoomUserInfo.Level = retValue.returnObject.Level;
            _RoomUserInfo.Level_Name = retValue.returnObject.Level_Name;
            _RoomUserInfo.Level_Next = retValue.returnObject.Level_Next;
            _RoomUserInfo.Level_Next_Name = retValue.returnObject.Level_Next_Name;
            _RoomUserInfo.VIP = retValue.returnObject.VIP;
            _RoomUserInfo.VIP_Expire = retValue.returnObject.VIP_Expire;
            _RoomUserInfo.Coin = retValue.returnObject.Coin;
            _RoomUserInfo.Beans = retValue.returnObject.Beans;
            _RoomUserInfo.IsAnchor = retValue.returnObject.IsAnchor;
            _RoomUserInfo.IsFamily = retValue.returnObject.IsFamily;
            _RoomUserInfo.IsAdmin = retValue.returnObject.IsAdmin;
            _RoomUserInfo.IsPhone = retValue.returnObject.IsPhone;
            _RoomUserInfo.EmblemList = retValue.returnObject.EmblemList;
            callback();
          })
        }
      ], function (retValue) {
        if (retValue) {
          if (Value.Timeout && Value.TimeoutCurrent < Value.TimeoutMAX) {
            setTimeout(function () {
              DAL_Factory.Business.RedisRoom_RoomUserInfo({
                RoomID: Value.RoomID,
                User_ID: Value.User_ID,
                Timeout: true,
                TimeoutCurrent: Value.TimeoutCurrent + 50
              }, callback);
            }, 50);
            return;
          }
          retValue.message = "用户已经退出了此房间";
          callback(retValue);
          return;
        }
        callback(KOC.ReturnValue.New({
          returnObject: _RoomUserInfo
        }));
      });
    },
    //endregion
    //region RedisRoom_Join:进入房间
    RedisRoom_Join: function (Value, callback) {
      Value = KOC.Lodash.extend({
        User_ID: null,
        NickName: null,
        RoomID: null,
        SocketID: null
      }, Value);
      Value.Join = true;
      Value.Guest = KOC.StringUtils.ToIntPositive(Value.User_ID) <= 0;
      Value.RoomInfo = null;
      Value.RoomAnchorInfo = null;
      Value.RoomUserInfo = null;
      Value.MountsInfo = null;
      Value.GiftPondSetting = CommonUtils.Commodity.Gift.Pond;
      Value.GiftFloatSetting = CommonUtils.Commodity.Gift.Float;
      var RedisMulti = null;
      KOC.Async.series([
        //读取艺人信息(mysql)
        function (callback) {
          DAL_Factory.User.User_Anchor.Info(Value.RoomID, function (retValue) {
            if (retValue.hasError) {
              callback(retValue);
              return;
            }
            if (!retValue.returnObject) {
              retValue.hasError = true;
              retValue.message = "错误的房间号";
              callback(retValue);
              return;
            }
            if (retValue.returnObject.Status !== 0) {
              retValue.hasError = true;
              retValue.message = "此艺人已经锁定";
              callback(retValue);
              return;
            }
            Value.RoomID = retValue.returnObject.User_ID;
            Value.RoomTitle = retValue.returnObject.RoomTitle;
            Value.RoomNotice = retValue.returnObject.RoomNotice;
            Value.RoomAnchorInfo = {
              RoomID: Value.RoomID,
              RoomName: retValue.returnObject.RoomName,
              RoomWelcome: retValue.returnObject.RoomWelcome,
              Pomelo: retValue.returnObject.Pomelo,
              EXP: retValue.returnObject.EXP,
              EXP_Next: retValue.returnObject.EXP_Next,
              EXP_Difference: retValue.returnObject.EXP_Difference,
              Level: retValue.returnObject.Level,
              Level_Name: retValue.returnObject.Level_Name,
              Level_Next: retValue.returnObject.Level_Next,
              Level_Next_Name: retValue.returnObject.Level_Next_Name,
              Tags: retValue.returnObject.Tags,
              Family_ID: retValue.returnObject.Family_ID
            };
            callback();
          });
        },
        //读取艺人用户信息(mysql)
        function (callback) {
          DAL_Factory.User.User_Info.Info(Value.RoomID, function (retValue) {
            if (retValue.hasError) {
              callback(retValue);
              return;
            }
            if (!retValue.returnObject) {
              retValue.hasError = true;
              retValue.message = "错误的房间号(1)";
              return;
            }
            if (!retValue.returnObject.IsAnchor) {
              retValue.hasError = true;
              retValue.message = "错误的房间号(2)";
              callback(retValue);
              return;
            }
            if (retValue.returnObject.Status === 1) {
              retValue.hasError = true;
              retValue.message = "此房间已被管理冻结";
              callback(retValue);
              return;
            }
            if (retValue.returnObject.Status !== 0) {
              retValue.hasError = true;
              retValue.message = "此房间艺人状态不可用(" + retValue.returnObject.Status + ")";
              callback(retValue);
              return;
            }
            Value.RoomAnchorInfo.NickName = retValue.returnObject.NickName;
            Value.RoomAnchorInfo.Birthday = retValue.returnObject.Birthday;
            Value.RoomAnchorInfo.Constellation = retValue.returnObject.Constellation;
            Value.RoomAnchorInfo.Beans = retValue.returnObject.Beans;
            Value.RoomAnchorInfo.Fans = retValue.returnObject.Fans;
            Value.RoomAnchorInfo.Attention = retValue.returnObject.Attention;
            callback();
          });
        },
        //读取用户信息(mysql)
        function (callback) {
          if (Value.Guest) {
            callback();
            return;
          }
          DAL_Factory.User.User_Info.Info(Value.User_ID, function (retValue) {
            if (retValue.hasError) {
              callback(retValue);
              return;
            }
            if (!retValue.returnObject) {
              retValue.hasError = true;
              retValue.message = "没找到相关用户信息";
              return;
            }
            if (retValue.returnObject.Status !== 0) {
              retValue.hasError = true;
              retValue.message = "用户已经锁定";
              callback(retValue);
              return;
            }
            Value.RoomUserInfo = {
              User_ID: retValue.returnObject.User_ID,
              NickName: retValue.returnObject.NickName,
              Sex: retValue.returnObject.Sex,
              Pomelo: retValue.returnObject.Pomelo,
              EXP: retValue.returnObject.EXP,
              EXP_Next: retValue.returnObject.EXP_Next,
              EXP_Difference: retValue.returnObject.EXP_Difference,
              Level: retValue.returnObject.Level,
              Level_Name: retValue.returnObject.Level_Name,
              Level_Next: retValue.returnObject.Level_Next,
              Level_Next_Name: retValue.returnObject.Level_Next_Name,
              VIP: retValue.returnObject.VIP,
              VIP_Expire: retValue.returnObject.VIP_Expire,
              Coin: retValue.returnObject.Coin,
              Beans: retValue.returnObject.Beans,
              IsAnchor: retValue.returnObject.IsAnchor,
              IsFamily: retValue.returnObject.IsFamily,
              IsAdmin: retValue.returnObject.IsAdmin,
              IsPhone: retValue.returnObject.Phone ? 1 : 0
            };
            Value.MountsInfo = retValue.returnObject.Mounts_ID > 0 ? retValue.returnObject.Mounts_ID : null;
            callback();
          });
        },
        //读取房间黑名单(mysql)
        function (callback) {
          if (Value.Guest) {
            callback();
            return;
          }
          DAL_Factory.User.User_Anchor_Blacklist.Info(Value.User_ID, Value.RoomID, function (retValue) {
            if (retValue.hasError) {
              callback(retValue);
              return;
            }
            if (retValue.returnObject && retValue.returnObject.Join) {
              retValue.errorCode = 999;
              retValue.hasError = true;
              retValue.message = "您已被禁止进入此房间.有限日期至:" + (retValue.returnObject.Join_Expire ? KOC.Moment(retValue.returnObject.Join_Expire).format("YYYY/MM/DD HH:mm:ss") : "永久")
              callback(retValue);
              return;
            }
            if (retValue.returnObject && retValue.returnObject.Shutup) {
              Value.RoomUserInfo.RoomBlack = true;
              Value.RoomUserInfo.RoomBlack_Shutup_Expire = retValue.returnObject.Shutup_Expire;
            }
            callback();
          });
        },
        //取得用户座骑-商城自选(mysql)
        function (callback) {
          if (Value.Guest || !Value.MountsInfo) {
            callback();
            return;
          }
          DAL_Factory.User.User_Mounts.Info(Value.User_ID, Value.MountsInfo, function (retValue) {
            if (retValue.hasError) {
              callback(retValue);
              return;
            }
            if (!retValue.returnObject || retValue.returnObject.Mounts_ExpireStatus !== 0) {
              Value.MountsInfo = null;
            }
            callback();
          });
        },
        //读取房间管理员(mysql)
        function (callback) {
          if (Value.Guest) {
            callback();
            return;
          }
          DAL_Factory.User.User_Anchor_Admin.Info(Value.User_ID, Value.RoomID, function (retValue) {
            if (retValue.hasError) {
              callback(retValue);
              return;
            }
            if (retValue.returnObject) {
              Value.RoomUserInfo.RoomAdmin = true;
            }
            callback();
          });
        },
        //读取房间守护(mysql)
        function (callback) {
          if (Value.Guest) {
            callback();
            return;
          }
          DAL_Factory.User.User_Anchor_Guardian.Info(null, Value.User_ID, Value.RoomID, function (retValue) {
            if (retValue.hasError) {
              callback(retValue);
              return;
            }
            if (retValue.returnObject && retValue.returnObject.Guardian_ExpireStatus === 0) {
              Value.RoomUserInfo.RoomGuardian = true;
              Value.RoomUserInfo.RoomGuardian_Mode = retValue.returnObject.Guardian_Mode;
              Value.RoomUserInfo.RoomGuardian_Expire = retValue.returnObject.Guardian_Expire;
            }
            callback();
          });
        },
        //读取房间艺人徽章信息-李响修改，时间：2016.08.23，原因：房间里显示用户和艺人的徽章
        function (callback) {
          DAL_Factory.User.User_Emblem.List(Value.RoomID, function (retValue) {
            if (retValue.hasError) {
              callback(retValue);
              return;
            }
            Value.RoomAnchorInfo.EmblemList = retValue.returnObject && retValue.returnObject.length > 0 ? JSON.stringify(retValue.returnObject) : null;
            callback();
          });
        },
        //读取用户徽章信息
        function (callback) {
          if (Value.Guest) {
            callback();
            return;
          }
          DAL_Factory.User.User_Emblem.List(Value.User_ID, function (retValue) {
            if (retValue.hasError) {
              callback(retValue);
              return;
            }
            Value.RoomUserInfo.EmblemList = retValue.returnObject && retValue.returnObject.length > 0 ? JSON.stringify(retValue.returnObject) : null;
            callback();
          });
        },
        //读取用户是否关注房间艺人(mysql)
        function (callback) {
          if (Value.Guest) {
            callback();
            return;
          }
          DAL_Factory.User.User_Attention.Info(Value.User_ID, Value.RoomID, function (retValue) {
            if (retValue.hasError) {
              callback(retValue);
              return;
            }
            if (retValue.returnObject) {
              Value.RoomUserInfo.RoomAttention = true;
            }
            callback();
          });
        },
        //监听RoomInfo
        function (callback) {
          DAL_Factory.RedisRoom.RoomInfo.Watch(Value.RoomID, function (retValue) {
            if (retValue.hasError) {
              callback(retValue);
              return;
            }
            callback();
          });
        },
        //判断RoomInfo是否存在
        function (callback) {
          DAL_Factory.RedisRoom.RoomInfo.Exists(Value.RoomID, function (retValue) {
            if (retValue.hasError) {
              callback(retValue);
              return;
            }
            Value.RoomExists = retValue.returnObject;
            callback();
          });
        },
        //判断是否是新进用户
        function (callback) {
          if (Value.Guest) {
            callback();
            return;
          }
          DAL_Factory.RedisRoom.Room_UserInfo_Socket.Exists(Value.RoomID, Value.User_ID, function (retValue) {
            if (retValue.hasError) {
              callback(retValue);
              return;
            }
            Value.Join = !retValue.returnObject;
            callback();
          });
        },
        //开启事务
        function (callback) {
          var retValue = KOC.RedisHelper.Multi(Config.Redis.DB.Room);
          if (retValue.hasError) {
            callback(retValue);
            return;
          }
          RedisMulti = retValue.returnObject;
          callback();
        },
        //写入用户信息
        function (callback) {
          if (Value.Guest) {
            callback();
            return;
          }
          DAL_Factory.RedisRoom.UserInfo.Set(RedisMulti, {
            User_ID: Value.RoomUserInfo.User_ID,
            NickName: Value.RoomUserInfo.NickName,
            Sex: Value.RoomUserInfo.Sex,
            Pomelo: Value.RoomUserInfo.Pomelo,
            EXP: Value.RoomUserInfo.EXP,
            EXP_Next: Value.RoomUserInfo.EXP_Next,
            EXP_Difference: Value.RoomUserInfo.EXP_Difference,
            Level: Value.RoomUserInfo.Level,
            Level_Name: Value.RoomUserInfo.Level_Name,
            Level_Next: Value.RoomUserInfo.Level_Next,
            Level_Next_Name: Value.RoomUserInfo.Level_Next_Name,
            VIP: Value.RoomUserInfo.VIP,
            VIP_Expire: Value.RoomUserInfo.VIP_Expire,
            Coin: Value.RoomUserInfo.Coin,
            Beans: Value.RoomUserInfo.Beans,
            IsAnchor: Value.RoomUserInfo.IsAnchor,
            IsFamily: Value.RoomUserInfo.IsFamily,
            IsAdmin: Value.RoomUserInfo.IsAdmin,
            IsPhone: Value.RoomUserInfo.IsPhone,
            EmblemList: Value.RoomUserInfo.EmblemList
          }, function (retValue) {
            if (retValue.hasError) {
              callback(retValue);
              return;
            }
            callback();
          });
        },
        //新建房间信息
        function (callback) {
          if (Value.RoomExists) {
            callback();
            return;
          }
          DAL_Factory.RedisRoom.RoomInfo.Set(RedisMulti, {
            RoomID: Value.RoomID,
            RoomTitle: Value.RoomTitle,
            RoomNotice: Value.RoomNotice
          }, function (retValue) {
            if (retValue.hasError) {
              callback(retValue);
              return;
            }
            callback();
          });
        },
        //写入房间艺人信息
        function (callback) {
          DAL_Factory.RedisRoom.Room_AnchorInfo.Set(RedisMulti, {
            RoomID: Value.RoomAnchorInfo.RoomID,
            RoomName: Value.RoomAnchorInfo.RoomName,
            RoomWelcome: Value.RoomAnchorInfo.RoomWelcome,
            NickName: Value.RoomAnchorInfo.NickName,
            Birthday: Value.RoomAnchorInfo.Birthday,
            Constellation: Value.RoomAnchorInfo.Constellation,
            Beans: Value.RoomAnchorInfo.Beans,
            Pomelo: Value.RoomAnchorInfo.Pomelo,
            EXP: Value.RoomAnchorInfo.EXP,
            EXP_Next: Value.RoomAnchorInfo.EXP_Next,
            EXP_Difference: Value.RoomAnchorInfo.EXP_Difference,
            Level: Value.RoomAnchorInfo.Level,
            Level_Name: Value.RoomAnchorInfo.Level_Name,
            Level_Next: Value.RoomAnchorInfo.Level_Next,
            Level_Next_Name: Value.RoomAnchorInfo.Level_Next_Name,
            Fans: Value.RoomAnchorInfo.Fans,
            Tags: Value.RoomAnchorInfo.Tags,
            Attention: Value.RoomAnchorInfo.Attention,
            Family_ID: Value.RoomAnchorInfo.Family_ID,
            EmblemList: Value.RoomAnchorInfo.EmblemList
          }, function (retValue) {
            if (retValue.hasError) {
              callback(retValue);
              return;
            }
            callback();
          });
        },
        //写入房间用户列表
        function (callback) {
          DAL_Factory.RedisRoom.Room_UserList.Add(RedisMulti, Value.RoomID, Value.User_ID, (
            (!Value.Guest && Value.RoomUserInfo.RoomAdmin ? 1000000 : 0)
            + (!Value.Guest && Value.RoomID == KOC.StringUtils.ToIntPositive(Value.User_ID) ? 100000 : 0)
            + (!Value.Guest && Value.RoomUserInfo.RoomGuardian ? 10000 : 0)
            + (!Value.Guest && Value.RoomUserInfo.VIP ? 1000 : 0)
            + (!Value.Guest ? 100 : 0)
            + (!Value.Guest ? Value.RoomUserInfo.Level : 0)
          ), function (retValue) {
            if (retValue.hasError) {
              callback(retValue);
              return;
            }
            callback();
          });
        },
        //写入房间用户信息
        function (callback) {
          DAL_Factory.RedisRoom.Room_UserInfo.Set(RedisMulti, {
            RoomID: Value.RoomID,
            Guest: Value.Guest,
            User_ID: Value.Guest ? Value.User_ID : Value.RoomUserInfo.User_ID,
            NickName: Value.Guest ? Value.NickName : Value.RoomUserInfo.NickName,
            Admin: Value.Guest ? false : Value.RoomUserInfo.RoomAdmin,
            Guardian: Value.Guest ? false : Value.RoomUserInfo.RoomGuardian,
            Guardian_Mode: Value.Guest ? "" : Value.RoomUserInfo.RoomGuardian_Mode,
            Guardian_Expire: Value.Guest ? null : Value.RoomUserInfo.RoomGuardian_Expire,
            Black: Value.Guest ? false : Value.RoomUserInfo.RoomBlack,
            Black_Shutup_Expire: Value.Guest ? null : Value.RoomUserInfo.RoomBlack_Shutup_Expire,
            EmblemList: Value.Guest ? "" : Value.RoomUserInfo.EmblemList,
            SocketID: Value.SocketID
          }, function (retValue) {
            if (retValue.hasError) {
              callback(retValue);
              return;
            }
            callback();
          });
        },
        //写入房间用户Socket连接
        function (callback) {
          if (Value.Guest) {
            callback();
            return;
          }
          DAL_Factory.RedisRoom.Room_UserInfo_Socket.Add(RedisMulti, Value.RoomID, Value.User_ID, Value.SocketID, function (retValue) {
            if (retValue.hasError) {
              callback(retValue);
              return;
            }
            callback();
          });
        },
        //提交事务
        function (callback) {
          KOC.RedisHelper.Exec(RedisMulti, function (retValue) {
            if (retValue.hasError) {
              RedisMulti = null;
              callback(retValue);
              return;
            }
            callback();
          });
        },
        //取得房间信息
        function (callback) {
          DAL_Factory.RedisRoom.RoomInfo.Get(Value.RoomID, function (retValue) {
            if (retValue.hasError) {
              callback(retValue);
              return;
            }
            Value.RoomInfo = retValue.returnObject;
            callback();
          });
        },
        //取得房间艺人信息
        function (callback) {
          DAL_Factory.RedisRoom.Room_AnchorInfo.Get(Value.RoomID, function (retValue) {
            if (retValue.hasError) {
              callback(retValue);
              return;
            }
            Value.RoomAnchorInfo = retValue.returnObject;
            callback();
          });
        },
        //取得房间用户信息
        function (callback) {
          DAL_Factory.Business.RedisRoom_RoomUserInfo({
            RoomID: Value.RoomID,
            User_ID: Value.User_ID
          }, function (retValue) {
            if (retValue.hasError) {
              callback(retValue);
              return;
            }
            Value.RoomUserInfo = retValue.returnObject;
            callback();
          });
        },
        //取得房间守护列表
        function (callback) {
          // DAL_Factory.User.User_Anchor_Guardian.List(socket.RoomID, function (retValue) {
          //     if (retValue.hasError) {
          //         socket.emit("AdminList", {
          //             flag: retValue.errorCode,
          //             message: retValue.message
          //         });
          //         return;
          //     }
          //     var _RoomAdminList = [];
          //     KOC.Lodash.forEach(retValue.returnObject, function (ThisValue) {
          //         //计算等级信息
          //         var _LevelInfo = CommonUtils.User.Level.fnLevelInfo(KOC.StringUtils.ToIntPositive(ThisValue.EXP));
          //         //计算VIP信息
          //         ThisValue.VIP_ExpireDay = 0;
          //         if (ThisValue.VIP && ThisValue.VIP_Expire && KOC.Moment().isAfter(KOC.Moment(ThisValue.VIP_Expire))) {
          //             ThisValue.VIP = false;
          //         }
          //         if (ThisValue.VIP && ThisValue.VIP_Expire) {
          //             ThisValue.VIP_ExpireDay = KOC.Moment(ThisValue.VIP_Expire).diff(KOC.Moment(), "days") < 0 ? 0 : KOC.Moment(ThisValue.VIP_Expire).diff(KOC.Moment(), "days");
          //         }
          //         _RoomAdminList.push({
          //             User_ID: ThisValue.User_ID,
          //             NickName: ThisValue.NickName,
          //             EXP: _LevelInfo.EXP,
          //             EXP_Next: _LevelInfo.EXP_Next,
          //             EXP_Difference: _LevelInfo.EXP_Difference,
          //             Level: _LevelInfo.Level,
          //             Level_Name: _LevelInfo.Level_Name,
          //             Level_Next: _LevelInfo.Level_Next,
          //             Level_Next_Name: _LevelInfo.Level_Next_Name,
          //             VIP: !!ThisValue.VIP,
          //             VIP_Expire: ThisValue.VIP_Expire,
          //             VIP_ExpireDay: ThisValue.VIP_ExpireDay
          //         });
          //     });
          //     //通知用户列表
          //     socket.emit("AdminList", {
          //         flag: 0,
          //         message: "",
          //         Data: KOC.Lodash.sortBy(_RoomAdminList, function (ThisValue) {
          //             return ((ThisValue.VIP ? 100 : 0) + ThisValue.Level) * -1;
          //         })
          //     });
          // });

          callback();
        },
        //计算用户座骑
        function (callback) {
          if (Value.Guest) {
            callback();
            return;
          }
          //守护座骑
          if (!Value.MountsInfo && Value.RoomUserInfo.RoomGuardian) {
            Value.MountsInfo = "Guardian-" + Value.RoomUserInfo.RoomGuardian_Mode;
          }
          if (!Value.MountsInfo && Value.RoomUserInfo.Level >= 10) {
            Value.MountsInfo = "Level-" + Value.RoomUserInfo.Level;
          }
          //取得座骑信息
          if (Value.MountsInfo) {
            Value.MountsInfo = CommonUtils.Commodity.Mounts.fnInfo(Value.MountsInfo);
          }
          callback();
        },
        //取得用户包裹信息
        function (callback) {
          if (Value.Guest) {
            Value.UserPackage = [];
            callback();
            return;
          }
          DAL_Factory.User.User_Package.List(Value.User_ID, function (retValue) {
            if (retValue.hasError) {
              callback(retValue);
              return;
            }
            Value.UserPackage = retValue.returnObject;
            callback();
          });
        },
        //取得用户是否关注房间艺人
        function (callback) {
          if (Value.Guest) {
            Value.Attention = false;
            callback();
            return;
          }
          DAL_Factory.User.User_Attention.Info(Value.User_ID, Value.RoomID, function (retValue) {
            if (retValue.hasError) {
              callback(retValue);
              return;
            }
            Value.Attention = !!retValue.returnObject;
            callback();
          });
        },
        //取得礼物浮动信息
        function (callback) {
          DAL_Factory.RedisRoom.Room_GiftFloat.Get(Value.RoomID, Value.GiftFloatSetting.Duration, function (retValue) {
            if (retValue.hasError) {
              callback(retValue);
              return;
            }
            Value.GiftFloat = retValue.returnObject;
            callback();
          });
        },
        //取得礼物头条信息
        function (callback) {
          DAL_Factory.RedisRoom.GiftHeadline.Get(function (retValue) {
            if (retValue.hasError) {
              callback(retValue);
              return;
            }
            Value.GiftHeadline = retValue.returnObject;
            callback();
          });
        },
        //取得房间奖池信息
        function (callback) {
          DAL_Factory.RedisRoom.Room_GiftPond.Get(Value.RoomID, function (retValue) {
            if (retValue.hasError) {
              callback(retValue);
              return;
            }
            Value.GiftPond = {
              TriggerAmt: Value.GiftPondSetting.TriggerAmt,//奖池触发金额
              Amt: retValue.returnObject//奖池已累计金额
            };
            callback();
          });
        }
      ], function (retValue) {
        if (retValue) {
          //撤销事务
          KOC.RedisHelper.Discard(RedisMulti);
          callback(retValue);
          return;
        }
        callback(KOC.ReturnValue.New({
          returnObject: {
            Join: Value.Join,
            RoomInfo: Value.RoomInfo,
            RoomAnchorInfo: Value.RoomAnchorInfo,
            RoomUserInfo: Value.RoomUserInfo,
            UserPackage: Value.UserPackage,
            MountsInfo: Value.MountsInfo,
            Attention: Value.Attention,
            GiftFloat: Value.GiftFloat,
            GiftHeadline: Value.GiftHeadline,
            GiftPond: Value.GiftPond,
            CreateDate: new Date()
          }
        }));
      });
    },
    //endregion
    //region RedisRoom_Live:开始直播
    RedisRoom_Live: function (Value, callback) {
      Value = KOC.Lodash.extend({
        User_ID: null,
        SocketID: null,
        IsMobile: null,
        Mode: null,
        RoomTitle: null,
        RoomNotice: null,
        Create_IP: null
      }, Value);
      var RedisMulti = null;
      if (!Value.SocketID) {
        callback(KOC.ReturnValue.New({
          hasError: true,
          message: "参数错误[SocketID]"
        }));
        return;
      }
      // if (!Value.RoomTitle) {
      //     callback(KOC.ReturnValue.New({
      //         hasError: true,
      //         message: "请填写直播标题[RoomTitle]"
      //     }));
      //     return;
      // }
      KOC.Async.series([
        //开始直播(mysql)
        function (callback) {
          DAL_Factory.Business.User_AnchorLive({
            User_ID: Value.User_ID,
            IsMobile: Value.IsMobile,
            Mode: Value.Mode,
            RoomTitle: Value.RoomTitle,
            RoomNotice: Value.RoomNotice,
            Create_IP: Value.Create_IP
          }, function (retValue) {
            if (retValue.hasError) {
              callback(retValue);
              return;
            }
            Value.Order_No = retValue.returnObject.Order_No;
            callback();
          });
        },
        //开启事务
        function (callback) {
          var retValue = KOC.RedisHelper.Multi(Config.Redis.DB.Room);
          if (retValue.hasError) {
            callback(retValue);
            return;
          }
          RedisMulti = retValue.returnObject;
          callback();
        },
        //开始直播
        function (callback) {
          DAL_Factory.RedisRoom.RoomInfo.Set_Live(RedisMulti, {
            RoomID: Value.User_ID,
            Order_No: Value.Order_No,
            SocketID: Value.SocketID,
            IsMobile: Value.IsMobile,
            Mode: Value.Mode,
            RoomTitle: Value.RoomTitle,
            RoomNotice: Value.RoomNotice
          }, function (retValue) {
            if (retValue.hasError) {
              callback(retValue);
              return;
            }
            callback();
          });
        },
        //提交事务
        function (callback) {
          KOC.RedisHelper.Exec(RedisMulti, function (retValue) {
            if (retValue.hasError) {
              RedisMulti = null;
              callback(retValue);
              return;
            }
            callback();
          });
        },
        //读取房间信息
        function (callback) {
          DAL_Factory.RedisRoom.RoomInfo.Get(Value.User_ID, function (retValue) {
            if (retValue.hasError) {
              callback(retValue);
              return;
            }
            Value.RoomInfo = retValue.returnObject;
            callback();
          });
        }
      ], function (retValue) {
        if (retValue) {
          //撤销事务
          KOC.RedisHelper.Discard(RedisMulti);
          callback(retValue);
          return;
        }
        callback(KOC.ReturnValue.New({
          returnObject: {
            Live_PUSH: Value.RoomInfo.Live_PUSH + Value.RoomInfo.Live_Code,
            RoomInfo: Value.RoomInfo,
            CreateDate: new Date()
          }
        }));
      });
    },
    //endregion
    //region RedisRoom_LiveEnd:结束直播
    RedisRoom_LiveEnd: function (Value, callback) {
      Value = KOC.Lodash.extend({
        RoomID: null,
        SocketID: null,
        IsAdmin: null
      }, Value);
      var RedisMulti = null;
      KOC.Async.series([
        //监听RoomInfo
        function (callback) {
          DAL_Factory.RedisRoom.RoomInfo.Watch(Value.RoomID, function (retValue) {
            if (retValue.hasError) {
              callback(retValue);
              return;
            }
            callback();
          });
        },
        //读取房间信息
        function (callback) {
          DAL_Factory.RedisRoom.RoomInfo.Get(Value.RoomID, function (retValue) {
            if (retValue.hasError) {
              callback(retValue);
              return;
            }
            if (!retValue.returnObject.Live) {
              retValue.hasError = true;
              retValue.message = "此房间没有开始直播";
              callback(retValue);
              return;
            }
            if (!Value.IsAdmin && retValue.returnObject.Live_SocketID != Value.SocketID) {
              retValue.hasError = true;
              retValue.message = "此连接没有开启任何直播";
              callback(retValue);
              return;
            }
            callback();
          });
        },
        //开启事务
        function (callback) {
          var retValue = KOC.RedisHelper.Multi(Config.Redis.DB.Room);
          if (retValue.hasError) {
            callback(retValue);
            return;
          }
          RedisMulti = retValue.returnObject;
          callback();
        },
        //结束直播
        function (callback) {
          DAL_Factory.RedisRoom.RoomInfo.Set_LiveEnd(RedisMulti, Value.RoomID, function (retValue) {
            if (retValue.hasError) {
              callback(retValue);
              return;
            }
            callback();
          });
        },
        //提交事务
        function (callback) {
          KOC.RedisHelper.Exec(RedisMulti, function (retValue) {
            if (retValue.hasError) {
              RedisMulti = null;
              callback(retValue);
              return;
            }
            callback();
          });
        },
        //结束直播(mysql)
        function (callback) {
          DAL_Factory.Business.User_AnchorLiveEnd(Value.RoomID, function (retValue) {
            if (retValue.hasError) {
              callback(retValue);
              return;
            }
            callback();
          });
        },
        //读取房间信息
        function (callback) {
          DAL_Factory.RedisRoom.RoomInfo.Get(Value.RoomID, function (retValue) {
            if (retValue.hasError) {
              callback(retValue);
              return;
            }
            Value.RoomInfo = retValue.returnObject;
            callback();
          });
        }
      ], function (retValue) {
        if (retValue) {
          //撤销事务
          KOC.RedisHelper.Discard(RedisMulti);
          callback(retValue);
          return;
        }
        callback(KOC.ReturnValue.New({
          returnObject: {
            RoomInfo: Value.RoomInfo,
            CreateDate: new Date()
          }
        }));
      });
    },
    //endregion
    //region RedisRoom_Disconnect:断开连接
    RedisRoom_Disconnect: function (Value, callback) {
      Value = KOC.Lodash.extend({
        User_ID: null,
        RoomID: null,
        SocketID: null
      }, Value);
      var RedisMulti = null;
      KOC.Async.series([
        //结束直播
        function (callback) {
          if (KOC.StringUtils.ToIntPositive(Value.User_ID) <= 0) {
            callback();
            return;
          }
          DAL_Factory.Business.RedisRoom_LiveEnd({
            RoomID: Value.RoomID,
            User_ID: Value.User_ID,
            SocketID: Value.SocketID
          }, function (retValue) {
            if (retValue.hasError) {
              callback();
              return;
            }
            Value.RoomInfo = retValue.returnObject.RoomInfo;
            callback();
          });
        },
        //读取RoomUserInfo
        function (callback) {
          DAL_Factory.Business.RedisRoom_RoomUserInfo({
            RoomID: Value.RoomID,
            User_ID: Value.User_ID,
            Timeout: true
          }, function (retValue) {
            if (retValue.hasError) {
              callback(retValue);
              return;
            }
            Value.RoomUserInfo = retValue.returnObject;
            callback();
          });
        },
        //删除登录用户socket
        function (callback) {
          if (Value.RoomUserInfo.Guest) {
            callback();
            return;
          }
          DAL_Factory.RedisRoom.Room_UserInfo_Socket.Remove(Value.RoomID, Value.User_ID, Value.SocketID, function (retValue) {
            if (retValue.hasError) {
              callback(retValue);
              return;
            }
            callback();
          });
        },
        //监听Room_UserInfo_Socket
        function (callback) {
          if (Value.RoomUserInfo.Guest) {
            callback();
            return;
          }
          DAL_Factory.RedisRoom.Room_UserInfo_Socket.Watch(Value.RoomID, Value.User_ID, function (retValue) {
            if (retValue.hasError) {
              callback(retValue);
              return;
            }
            callback();
          });
        },
        //判断登录用户是否还存在socket连接
        function (callback) {
          if (Value.RoomUserInfo.Guest) {
            callback();
            return;
          }
          DAL_Factory.RedisRoom.Room_UserInfo_Socket.Exists(Value.RoomID, Value.User_ID, function (retValue) {
            if (retValue.hasError) {
              callback(retValue);
              return;
            }
            Value.SocketExists = retValue.returnObject;
            callback();
          });
        },
        //开启事务
        function (callback) {
          var retValue = KOC.RedisHelper.Multi(Config.Redis.DB.Room);
          if (retValue.hasError) {
            callback(retValue);
            return;
          }
          RedisMulti = retValue.returnObject;
          callback();
        },
        //删除房间用户信息
        function (callback) {
          if (Value.SocketExists) {
            callback();
            return;
          }
          DAL_Factory.RedisRoom.Room_UserInfo.Del(RedisMulti, Value.RoomID, Value.User_ID, function (retValue) {
            if (retValue.hasError) {
              callback(retValue);
              return;
            }
            callback();
          });
        },
        //删除房间用户列表
        function (callback) {
          if (Value.SocketExists) {
            callback();
            return;
          }
          DAL_Factory.RedisRoom.Room_UserList.Remove(RedisMulti, Value.RoomID, Value.User_ID, function (retValue) {
            if (retValue.hasError) {
              callback(retValue);
              return;
            }
            callback();
          });
        },
        //删除用户信息
        function (callback) {
          callback();
        },
        //提交事务
        function (callback) {
          KOC.RedisHelper.Exec(RedisMulti, function (retValue) {
            if (retValue.hasError) {
              RedisMulti = null;
              callback(retValue);
              return;
            }
            callback();
          });
        }
      ], function (retValue) {
        if (retValue) {
          //撤销事务
          KOC.RedisHelper.Discard(RedisMulti);
          if (Value.RoomInfo) {
            retValue.returnObject = {
              RoomInfo: Value.RoomInfo
            };
          }
          callback(retValue);
          return;
        }
        callback(KOC.ReturnValue.New({
          returnObject: {
            Out: !Value.SocketExists,
            RoomInfo: Value.RoomInfo,
            RoomUserInfo: Value.RoomUserInfo,
            CreateDate: new Date()
          }
        }));
      });
    },
    //endregion
    //region RedisRoom_Guardian:守护购买
    RedisRoom_Guardian: function (Value, callback) {
      Value = KOC.Lodash.extend({
        User_ID: null,
        User_ID_Guardian: null,
        Guardian_ID: null,
        Create_IP: null
      }, Value);
      var RedisMulti = null;
      KOC.Async.series([
        //读取房间用户信息
        function (callback) {
          DAL_Factory.Business.RedisRoom_RoomUserInfo({
            RoomID: Value.User_ID_Guardian,
            User_ID: Value.User_ID
          }, function (retValue) {
            if (retValue.hasError) {
              callback(retValue);
              return;
            }
            Value.RoomUserInfo = retValue.returnObject;
            callback();
          });
        },
        //购买守护(mysql)
        function (callback) {
          DAL_Factory.Business.User_GuardianPurchase({
            User_ID: Value.User_ID,
            User_ID_Guardian: Value.User_ID_Guardian,
            Guardian_ID: Value.Guardian_ID,
            Create_IP: Value.Create_IP
          }, function (retValue) {
            if (retValue.hasError) {
              callback(retValue);
              return;
            }
            Value.Order_Amt = retValue.returnObject.Order_Amt;
            Value.User_ID = retValue.returnObject.User_ID;
            Value.User_ID_Guardian = retValue.returnObject.User_ID_Guardian;
            Value.User_Pomelo = retValue.returnObject.User_Pomelo;
            Value.User_EXP = retValue.returnObject.User_EXP;
            Value.User_Coin = retValue.returnObject.User_Coin;
            Value.User_Guardian_Expire = retValue.returnObject.User_Guardian_Expire;
            Value.Anchor_Beans = retValue.returnObject.Anchor_Beans;
            Value.Anchor_Pomelo = retValue.returnObject.Anchor_Pomelo;
            Value.Anchor_EXP = retValue.returnObject.Anchor_EXP;
            Value.Anchor_Fans = retValue.returnObject.Anchor_Fans;
            Value.Anchor_Attention = retValue.returnObject.Anchor_Attention;
            Value.GuardianInfo = retValue.returnObject.GuardianInfo;
            callback();
          });
        },
        //开启事务
        function (callback) {
          var retValue = KOC.RedisHelper.Multi(Config.Redis.DB.Room);
          if (retValue.hasError) {
            callback(retValue);
            return;
          }
          RedisMulti = retValue.returnObject;
          callback();
        },
        //更新用户信息
        function (callback) {
          DAL_Factory.RedisRoom.UserInfo.Update(RedisMulti, {
            User_ID: Value.User_ID,
            Pomelo: Value.User_Pomelo,
            EXP: Value.User_EXP,
            Coin: Value.User_Coin
          }, function (retValue) {
            if (retValue.hasError) {
              callback(retValue);
              return;
            }
            callback();
          });
        },
        //更新房间用户信息
        function (callback) {
          DAL_Factory.RedisRoom.Room_UserInfo.Update(RedisMulti, {
            RoomID: Value.User_ID_Guardian,
            User_ID: Value.User_ID,
            Guardian: true,
            Guardian_Mode: Value.GuardianInfo.Mode,
            Guardian_Expire: Value.User_Guardian_Expire
          }, function (retValue) {
            if (retValue.hasError) {
              callback(retValue);
              return;
            }
            callback();
          });
        },
        //更新房间艺人信息
        function (callback) {
          DAL_Factory.RedisRoom.Room_AnchorInfo.Update(RedisMulti, {
            RoomID: Value.User_ID_Guardian,
            Beans: Value.Anchor_Beans,
            Pomelo: Value.Anchor_Pomelo,
            EXP: Value.Anchor_EXP,
            Fans: Value.Anchor_Fans,
            Attention: Value.Anchor_Attention
          }, function (retValue) {
            if (retValue.hasError) {
              callback(retValue);
              return;
            }
            callback();
          });
        },
        //提交事务
        function (callback) {
          KOC.RedisHelper.Exec(RedisMulti, function (retValue) {
            if (retValue.hasError) {
              RedisMulti = null;
              callback(retValue);
              return;
            }
            callback();
          });
        },
        //取得房间用户信息
        function (callback) {
          DAL_Factory.Business.RedisRoom_RoomUserInfo({
            RoomID: Value.User_ID_Guardian,
            User_ID: Value.User_ID
          }, function (retValue) {
            if (retValue.hasError) {
              callback(retValue);
              return;
            }
            Value.UserUpgrade = retValue.returnObject.Level != Value.RoomUserInfo.Level;
            Value.RoomUserInfo = retValue.returnObject;
            callback();
          });
        },
        //取得房间艺人信息
        function (callback) {
          DAL_Factory.RedisRoom.Room_AnchorInfo.Get(Value.User_ID_Guardian, function (retValue) {
            if (retValue.hasError) {
              callback(retValue);
              return;
            }
            Value.RoomAnchorInfo = retValue.returnObject;
            callback();
          });
        }
      ], function (retValue) {
        if (retValue) {
          //撤销事务
          KOC.RedisHelper.Discard(RedisMulti);
          callback(retValue);
          return;
        }
        callback(KOC.ReturnValue.New({
          returnObject: {
            Order_Amt: Value.Order_Amt,
            UserUpgrade: Value.UserUpgrade,
            RoomAnchorInfo: Value.RoomAnchorInfo,
            RoomUserInfo: Value.RoomUserInfo,
            GuardianInfo: Value.GuardianInfo,
            CreateDate: new Date()
          }
        }));
      });
    },
    //endregion
    //region RedisRoom_Gift:礼物购买
    RedisRoom_Gift: function (Value, callback) {
      Value = KOC.Lodash.extend({
        PurchaseMode: null, //购买模式 0:先使用包裹再购买 1:只购买 2:只使用包裹
        User_ID_Anchor: null,
        User_ID: null,
        User_ID_Gift: null,
        Gift_ID: null,
        Num: null,
        Create_IP: null
      }, Value);
      var RedisMulti = null;
      KOC.Async.series([
        //读取房间用户信息(赠送者)
        function (callback) {
          DAL_Factory.Business.RedisRoom_RoomUserInfo({
            RoomID: Value.User_ID_Anchor,
            User_ID: Value.User_ID
          }, function (retValue) {
            if (retValue.hasError) {
              callback(retValue);
              return;
            }
            Value.RoomUserInfo = retValue.returnObject;
            callback();
          });
        },
        //取得房间用户信息(被赠送者)
        function (callback) {
          if (Value.User_ID_Gift == Value.User_ID_Anchor) {
            callback();
            return;
          }
          DAL_Factory.Business.RedisRoom_RoomUserInfo({
            RoomID: Value.User_ID_Anchor,
            User_ID: Value.User_ID_Gift
          }, function (retValue) {
            if (retValue.hasError) {
              callback(retValue);
              return;
            }
            Value.RoomUserInfo_Gift = retValue.returnObject;
            callback();
          });
        },
        //购买礼物(mysql)
        function (callback) {
          DAL_Factory.Business.User_GiftPurchase({
            PurchaseMode: Value.PurchaseMode,
            User_ID_Anchor: Value.User_ID_Anchor,
            User_ID: Value.User_ID,
            User_ID_Gift: Value.User_ID_Gift,
            Gift_ID: Value.Gift_ID,
            Num: Value.Num,
            Create_IP: Value.Create_IP
          }, function (retValue) {
            if (retValue.hasError) {
              callback(retValue);
              return;
            }
            Value.PurchaseMode = retValue.returnObject.PurchaseMode;
            Value.Order_Amt = retValue.returnObject.Order_Amt;
            Value.User_ID = retValue.returnObject.User_ID;
            Value.User_ID_Gift = retValue.returnObject.User_ID_Gift;
            Value.User_ID_Anchor = retValue.returnObject.User_ID_Anchor;
            Value.User_NickName = retValue.returnObject.User_NickName;
            Value.User_NickName_Gift = retValue.returnObject.User_NickName_Gift;
            Value.User_Pomelo = retValue.returnObject.User_Pomelo;
            Value.User_EXP = retValue.returnObject.User_EXP;
            Value.User_Coin = retValue.returnObject.User_Coin;
            Value.Anchor_Beans = retValue.returnObject.Anchor_Beans;
            Value.Anchor_Pomelo = retValue.returnObject.Anchor_Pomelo;
            Value.Anchor_EXP = retValue.returnObject.Anchor_EXP;
            Value.Anchor_Fans = retValue.returnObject.Anchor_Fans;
            Value.Anchor_Attention = retValue.returnObject.Anchor_Attention;
            Value.Num = retValue.returnObject.GiftNum;
            Value.GiftInfo = retValue.returnObject.GiftInfo;
            Value.LuckyCoin = retValue.returnObject.LuckyCoin;
            Value.LuckyMultipleList = retValue.returnObject.LuckyMultipleList;
            //连击判断
            if (Value.RoomUserInfo.RoomGiftLast_Date
              && Value.GiftInfo.id == Value.RoomUserInfo.RoomGiftLast_ID
              && Value.User_ID_Gift == Value.RoomUserInfo.RoomGiftLast_UserID
              && Value.Num == Value.RoomUserInfo.RoomGiftLast_Num
              && KOC.Moment().diff(Value.RoomUserInfo.RoomGiftLast_Date, "seconds") <= 4) {
              Value.Count = Value.RoomUserInfo.RoomGiftLast_Count + 1;
            } else {
              Value.Count = 1;
            }
            callback();
          });
        },
        //用户礼物排行榜维护(RedisCommon)
        function (callback) {
          DAL_Factory.Business.RedisCommon_GiftUserRankingSet({
            Gift_ID: Value.Gift_ID,
            User_ID: Value.User_ID,
            User_ID_Gift: Value.User_ID_Gift,
            Num: Value.Num
          }, function (retValue) {
            if (retValue.hasError) {
              callback(retValue);
              return;
            }
            callback();
          });
        },
        //开启事务
        function (callback) {
          var retValue = KOC.RedisHelper.Multi(Config.Redis.DB.Room);
          if (retValue.hasError) {
            callback(retValue);
            return;
          }
          RedisMulti = retValue.returnObject;
          callback();
        },
        //更新用户信息
        function (callback) {
          DAL_Factory.RedisRoom.UserInfo.Update(RedisMulti, {
            User_ID: Value.User_ID,
            Pomelo: Value.User_Pomelo,
            EXP: Value.User_EXP,
            Coin: Value.User_Coin
          }, function (retValue) {
            if (retValue.hasError) {
              callback(retValue);
              return;
            }
            callback();
          });
        },
        //更新房间用户信息
        function (callback) {
          DAL_Factory.RedisRoom.Room_UserInfo.Update(RedisMulti, {
            RoomID: Value.User_ID_Anchor,
            User_ID: Value.User_ID,
            GiftLast_ID: Value.GiftInfo.id,
            GiftLast_UserID: Value.User_ID_Gift,
            GiftLast_Num: Value.Num,
            GiftLast_Count: Value.Count
          }, function (retValue) {
            if (retValue.hasError) {
              callback(retValue);
              return;
            }
            callback();
          });
        },
        //更新房间艺人信息
        function (callback) {
          if (Value.User_ID_Gift != Value.User_ID_Anchor) {
            callback();
            return;
          }
          DAL_Factory.RedisRoom.Room_AnchorInfo.Update(RedisMulti, {
            RoomID: Value.User_ID_Anchor,
            Beans: Value.Anchor_Beans,
            Pomelo: Value.Anchor_Pomelo,
            EXP: Value.Anchor_EXP,
            Fans: Value.Anchor_Fans,
            Attention: Value.Anchor_Attention
          }, function (retValue) {
            if (retValue.hasError) {
              callback(retValue);
              return;
            }
            callback();
          });
        },
        //提交事务
        function (callback) {
          KOC.RedisHelper.Exec(RedisMulti, function (retValue) {
            if (retValue.hasError) {
              RedisMulti = null;
              callback(retValue);
              return;
            }
            callback();
          });
        },
        //浮动礼物维护
        function (callback) {
          if (Value.GiftInfo.IsFloat === false) {
            //礼物不浮动
            Value.GiftFloat = null;
            callback();
            return;
          }
          DAL_Factory.Business.RedisRoom_GiftFloat({
            RoomID: Value.User_ID_Anchor,
            User_ID: Value.User_ID,
            User_NickName: Value.User_NickName,
            User_ID_Gift: Value.User_ID_Gift,
            User_NickName_Gift: Value.User_NickName_Gift,
            GiftNum: Value.Num,
            GiftAmt: Value.Order_Amt,
            GiftInfo: Value.GiftInfo
          }, function (retValue) {
            if (retValue.hasError) {
              callback(retValue);
              return;
            }
            Value.GiftFloat = retValue.returnObject;
            callback();
          });
        },
        //头条信息维护
        function (callback) {
          if (Value.User_ID_Gift != Value.User_ID_Anchor) {
            callback();
            return;
          }
          if (Value.GiftInfo.IsHeadline === false) {
            //礼物不上头条
            Value.GiftHeadline = null;
            callback();
            return;
          }
          DAL_Factory.Business.RedisRoom_GiftHeadline({
            User_ID: Value.User_ID,
            User_NickName: Value.User_NickName,
            Anchor_ID: Value.User_ID_Gift,
            Anchor_NickName: Value.User_NickName_Gift,
            GiftNum: Value.Num,
            GiftAmt: Value.Order_Amt,
            GiftInfo: Value.GiftInfo
          }, function (retValue) {
            if (retValue.hasError) {
              callback(retValue);
              return;
            }
            Value.GiftHeadline = retValue.returnObject;
            callback();
          });
        },
        //奖池数据维护
        function (callback) {
          if (Value.GiftInfo.IsLucky) {
            //幸运礼物不累积奖池
            Value.GiftPond = null;
            callback();
            return;
          }
          if (Value.GiftInfo.IsPond === false) {
            //礼物不累积奖池
            Value.GiftPond = null;
            callback();
            return;
          }
          DAL_Factory.Business.RedisRoom_GiftPond({
            RoomID: Value.User_ID_Anchor,
            User_ID: Value.User_ID,
            Amt: Value.Order_Amt,
            Create_IP: Value.Create_IP
          }, function (retValue) {
            Value.GiftPond = {
              TriggerAmt: retValue.returnObject.GiftPondTriggerAmt,//奖池触发金额
              Amt: retValue.returnObject.GiftPondAmt,//奖池已累计金额
              Burst: retValue.returnObject.GiftPondBurst,//本次是否爆奖
              BurstAmt: retValue.returnObject.GiftPondBurstAmt,//本次爆奖金额
              BurstList: retValue.returnObject.GiftPondBurstList//本次获奖用户列表
            };
            callback();
          });
        },
        //取得房间用户信息
        function (callback) {
          DAL_Factory.Business.RedisRoom_RoomUserInfo({
            RoomID: Value.User_ID_Anchor,
            User_ID: Value.User_ID
          }, function (retValue) {
            if (retValue.hasError) {
              callback(retValue);
              return;
            }
            Value.UserUpgrade = retValue.returnObject.Level != Value.RoomUserInfo.Level;
            Value.RoomUserInfo = retValue.returnObject;
            callback();
          });
        },
        //取得房间艺人信息
        function (callback) {
          DAL_Factory.RedisRoom.Room_AnchorInfo.Get(Value.User_ID_Anchor, function (retValue) {
            if (retValue.hasError) {
              callback(retValue);
              return;
            }
            Value.RoomAnchorInfo = retValue.returnObject;
            callback();
          });
        },
        //取得用户包裹信息
        function (callback) {
          if (Value.Guest) {
            Value.UserPackage = [];
            callback();
            return;
          }
          DAL_Factory.User.User_Package.List(Value.User_ID, function (retValue) {
            if (retValue.hasError) {
              callback(retValue);
              return;
            }
            Value.UserPackage = retValue.returnObject;
            callback();
          });
        }
      ], function (retValue) {
        if (retValue) {
          //撤销事务
          KOC.RedisHelper.Discard(RedisMulti);
          callback(retValue);
          return;
        }
        callback(KOC.ReturnValue.New({
          returnObject: {
            Order_Amt: Value.Order_Amt,
            UserUpgrade: Value.UserUpgrade,
            RoomAnchorInfo: Value.RoomAnchorInfo,
            RoomUserInfo: Value.RoomUserInfo,
            RoomUserInfo_Gift: Value.RoomUserInfo_Gift,
            UserPackage: Value.UserPackage,
            GiftNum: Value.Num,
            GiftCount: Value.Count,
            GiftStreamer: Value.GiftInfo.Streamer && Value.Num >= Value.GiftInfo.Streamer.Num ? Value.GiftInfo.Streamer.Level : 0,
            GiftInfo: Value.GiftInfo,
            GiftFloat: Value.GiftFloat,
            GiftHeadline: Value.GiftHeadline,
            GiftPond: Value.GiftPond,
            LuckyCoin: Value.LuckyCoin,
            LuckyMultipleList: Value.LuckyMultipleList,
            CreateDate: new Date()
          }
        }));
      });
    },
    //endregion
    //region RedisRoom_GiftPond:礼物奖池维护
    RedisRoom_GiftPond: function (Value, callback) {
      Value = KOC.Lodash.extend({
        RoomID: null,
        User_ID: null,
        Amt: null,
        Create_IP: null
      }, Value);
      Value.RoomID = KOC.StringUtils.ToIntPositive(Value.RoomID);
      if (Value.RoomID <= 0) {
        callback(KOC.ReturnValue.New({
          hasError: true,
          message: "参数错误[RoomID]"
        }));
        return;
      }
      Value.User_ID = KOC.StringUtils.ToIntPositive(Value.User_ID);
      if (Value.User_ID <= 0) {
        callback(KOC.ReturnValue.New({
          hasError: true,
          message: "参数错误[User_ID]"
        }));
        return;
      }
      Value.Amt = KOC.StringUtils.ToIntPositive(Value.Amt);
      if (Value.Amt <= 0) {
        callback(KOC.ReturnValue.New({
          hasError: true,
          message: "参数错误[Amt]"
        }));
        return;
      }
      Value.GiftPondSetting = CommonUtils.Commodity.Gift.Pond;
      Value.GiftPondAmt = 0;
      Value.GiftPondBurst = false;
      Value.GiftPondBurstAmt = 0;
      Value.GiftPondBurstList = null;
      KOC.Async.series([
        //增加累计金额
        function (callback) {
          DAL_Factory.RedisRoom.Room_GiftPond.Update(Value.RoomID, Value.Amt, function (retValue) {
            if (retValue.hasError) {
              callback(retValue);
              return;
            }
            Value.GiftPondAmt = retValue.returnObject;
            Value.GiftPondBurst = Value.GiftPondAmt >= Value.GiftPondSetting.TriggerAmt;
            callback();
          });
        },
        //写入贡献用户
        function (callback) {
          DAL_Factory.RedisRoom.Room_GiftPond_User.Add(Value.RoomID, Value.User_ID, function (retValue) {
            if (retValue.hasError) {
              callback(retValue);
              return;
            }
            callback();
          });
        },
        //奖池爆奖
        function (callback) {
          if (!Value.GiftPondBurst) {
            callback();
            return;
          }
          DAL_Factory.Business.RedisRoom_GiftPondBurst({
            RoomID: Value.RoomID,
            GiftPondSetting: Value.GiftPondSetting,
            Create_IP: Value.Create_IP
          }, function (retValue) {
            if (retValue.hasError) {
              callback(retValue);
              return;
            }
            Value.GiftPondAmt = 0;
            Value.GiftPondBurstAmt = retValue.returnObject.GiftPondBurstAmt;
            Value.GiftPondBurstList = retValue.returnObject.GiftPondBurstList;
            Value.GiftPondBurst = Value.GiftPondBurstAmt > 0 && Value.GiftPondBurstList.length > 0;
            callback();
          });
        }
      ], function (retValue) {
        if (!retValue) {
          retValue = KOC.ReturnValue.New();
        }
        retValue.returnObject = {
          GiftPondTriggerAmt: Value.GiftPondSetting.TriggerAmt,//奖池触发金额
          GiftPondAmt: Value.GiftPondAmt,//奖池已累计金额
          GiftPondBurst: Value.GiftPondBurst,//本次是否爆奖
          GiftPondBurstAmt: Value.GiftPondBurstAmt,//本次爆奖金额
          GiftPondBurstList: Value.GiftPondBurstList//本次获奖用户列表
        };
        callback(retValue);
      });
    },
    //endregion
    //region RedisRoom_GiftPondBurst:礼物奖池爆奖
    RedisRoom_GiftPondBurst: function (Value, callback) {
      Value = KOC.Lodash.extend({
        RoomID: null,
        GiftPondSetting: null,
        Create_IP: null
      }, Value);
      Value.RoomID = KOC.StringUtils.ToIntPositive(Value.RoomID);
      if (Value.RoomID <= 0) {
        callback(KOC.ReturnValue.New({
          hasError: true,
          message: "参数错误[RoomID]"
        }));
        return;
      }
      if (Value.GiftPondSetting.TriggerAmt <= 0
        || Value.GiftPondSetting.MIN < 0
        || Value.GiftPondSetting.MAX < 0
        || Value.GiftPondSetting.MAX < Value.GiftPondSetting.MIN
        || Value.GiftPondSetting.TriggerAmt < Value.GiftPondSetting.MAX
        || Value.GiftPondSetting.Number <= 0
        || Value.GiftPondSetting.Number > Value.GiftPondSetting.MIN) {
        callback(KOC.ReturnValue.New({
          hasError: true,
          message: "奖池设置有误"
        }));
        return;
      }
      var RedisMulti = null;
      KOC.Async.series([
        //监听Room_GiftPond
        function (callback) {
          DAL_Factory.RedisRoom.Room_GiftPond.Watch(Value.RoomID, function (retValue) {
            if (retValue.hasError) {
              callback(retValue);
              return;
            }
            callback();
          });
        },
        //开启事务
        function (callback) {
          var retValue = KOC.RedisHelper.Multi(Config.Redis.DB.Room);
          if (retValue.hasError) {
            callback(retValue);
            return;
          }
          RedisMulti = retValue.returnObject;
          callback();
        },
        //读取Room_GiftPond
        function (callback) {
          DAL_Factory.RedisRoom.Room_GiftPond.Get(Value.RoomID, function (retValue) {
            if (retValue.hasError) {
              callback(retValue);
              return;
            }
            if (retValue.returnObject < Value.GiftPondSetting.TriggerAmt) {
              retValue.hasError = true;
              retValue.message = "开奖错误:未到累计金额";
              callback(retValue);
              return;
            }
            callback();
          });
        },
        //取得中奖用户
        function (callback) {
          DAL_Factory.RedisRoom.Room_GiftPond_User.Get(Value.RoomID, function (retValue) {
            if (retValue.hasError) {
              callback(retValue);
              return;
            }
            if (!retValue.returnObject || retValue.returnObject.length <= 0) {
              retValue.hasError = true;
              retValue.message = "取得中奖用户错误";
              callback(retValue);
              return;
            }
            Value.GiftPondUser = retValue.returnObject;
            callback();
          });
        },
        //重置Room_GiftPond
        function (callback) {
          DAL_Factory.RedisRoom.Room_GiftPond.Reset(RedisMulti, Value.RoomID, function (retValue) {
            if (retValue.hasError) {
              callback(retValue);
              return;
            }
            callback();
          });
        },
        //重置贡献用户
        function (callback) {
          DAL_Factory.RedisRoom.Room_GiftPond_User.Del(RedisMulti, Value.RoomID, function (retValue) {
            if (retValue.hasError) {
              callback(retValue);
              return;
            }
            callback();
          });
        },
        //提交事务
        function (callback) {
          KOC.RedisHelper.Exec(RedisMulti, function (retValue) {
            if (retValue.hasError) {
              RedisMulti = null;
              callback(retValue);
              return;
            }
            callback();
          });
        },
        //计算中奖用户(取得用户信息)
        function (callback) {
          //随机获奖用户
          KOC.Lodash.sortBy(Value.GiftPondUser, function () {
            return Math.random();
          });
          //计算获奖用户
          Value.GiftPondBurstList = [];
          KOC.Async.eachSeries(Value.GiftPondUser, function (ThisValue, callback) {
            DAL_Factory.Business.RedisRoom_RoomUserInfo({
              RoomID: Value.RoomID,
              User_ID: KOC.StringUtils.ToIntPositive(ThisValue)
            }, function (retValue) {
              if (retValue.hasError) {
                callback();
                return;
              }
              Value.GiftPondBurstList.push({
                Amt: 1,//奖池每人最小发放金币:1
                UserInfo: retValue.returnObject
              });
              if (Value.GiftPondBurstList.length >= Value.GiftPondSetting.Number) {
                callback(KOC.ReturnValue.New());
                return;
              }
              callback();
            });
          }, function () {
            callback();
          });
        },
        //计算开奖金额及分配
        function (callback) {
          //开奖金额
          Value.GiftPondBurstAmt = KOC.Lodash.random(Value.GiftPondSetting.MIN, Value.GiftPondSetting.MAX);
          //无中奖用户(所有用户已退出房间)
          if (Value.GiftPondBurstList.length <= 0) {
            Value.GiftPondBurstAmt = 0;
            callback();
            return;
          }
          //计算获奖人金额
          var _RemainAmt = Value.GiftPondBurstAmt - Value.GiftPondBurstList.length;//还需要分配的金额 减去每人最小发放金币:1
          KOC.Lodash.forEach(Value.GiftPondBurstList, function (ThisValue, i) {
            if (_RemainAmt <= 0) {
              return false;
            }
            if (i == Value.GiftPondBurstList.length - 1) {
              ThisValue.Amt += _RemainAmt;
              return false;
            }
            var _Amt = KOC.Lodash.random(_RemainAmt);
            _RemainAmt -= _Amt;
            ThisValue.Amt += _Amt;
          });
          callback();
        },
        //礼物爆奖(mysql)
        function (callback) {
          if (Value.GiftPondBurstList.length <= 0 || Value.GiftPondBurstAmt <= 0) {
            callback();
            return;
          }
          DAL_Factory.Business.User_GiftPond({
            RoomID: Value.RoomID,
            Amt: Value.GiftPondBurstAmt,
            Data: Value.GiftPondBurstList,
            Create_IP: Value.Create_IP
          }, function (retValue) {
            if (retValue.hasError) {
              callback(retValue);
              return;
            }
            callback();
          });
        }
      ], function (retValue) {
        if (retValue) {
          //撤销事务
          KOC.RedisHelper.Discard(RedisMulti);
          callback(retValue);
          return;
        }
        callback(KOC.ReturnValue.New({
          returnObject: {
            GiftPondBurstAmt: Value.GiftPondBurstAmt,
            GiftPondBurstList: Value.GiftPondBurstList
          }
        }));
      });
    },
    //endregion
    //region RedisRoom_GiftFloat:礼物浮动维护
    RedisRoom_GiftFloat: function (Value, callback) {
      Value = KOC.Lodash.extend({
        RoomID: null,
        User_ID: -1,
        User_NickName: null,
        User_ID_Gift: -1,
        User_NickName_Gift: null,
        GiftNum: 0,
        GiftAmt: 0,
        GiftInfo: null
      }, Value);
      if (!Value.GiftInfo) {
        callback(KOC.ReturnValue.New({
          hasError: true,
          message: "参数错误[GiftInfo]"
        }));
        return;
      }
      if (Value.GiftInfo.IsFloat === false) {
        callback(KOC.ReturnValue.New());
        return;
      }
      Value.RoomID = KOC.StringUtils.ToIntPositive(Value.RoomID);
      Value.User_ID = KOC.StringUtils.ToIntPositive(Value.User_ID);
      Value.User_ID_Gift = KOC.StringUtils.ToIntPositive(Value.User_ID_Gift);
      Value.GiftNum = KOC.StringUtils.ToIntPositive(Value.GiftNum);
      Value.GiftAmt = KOC.StringUtils.ToIntPositive(Value.GiftAmt);
      if (Value.RoomID <= 0) {
        callback(KOC.ReturnValue.New({
          hasError: true,
          message: "参数错误[RoomID]"
        }));
        return;
      }
      if (Value.User_ID <= 0) {
        callback(KOC.ReturnValue.New({
          hasError: true,
          message: "参数错误[User_ID]"
        }));
        return;
      }
      if (Value.User_ID_Gift <= 0) {
        callback(KOC.ReturnValue.New({
          hasError: true,
          message: "参数错误[User_ID_Gift]"
        }));
        return;
      }
      if (Value.GiftNum <= 0) {
        callback(KOC.ReturnValue.New({
          hasError: true,
          message: "参数错误[GiftNum]"
        }));
        return;
      }
      if (Value.GiftAmt < 0) {
        callback(KOC.ReturnValue.New({
          hasError: true,
          message: "参数错误[GiftAmt]"
        }));
        return;
      }
      //读取浮动设置
      var _Settings = CommonUtils.Commodity.Gift.Float;
      if (Value.GiftInfo.Price < _Settings.Price) {
        callback(KOC.ReturnValue.New());
        return;
      }
      Value.Duration = _Settings.Duration;
      var _Data = null;
      KOC.Async.series([
        //写入浮动
        function (callback) {
          DAL_Factory.RedisRoom.Room_GiftFloat.Add(Value, function (retValue) {
            if (retValue.hasError) {
              callback(retValue);
              return;
            }
            _Data = retValue.returnObject;
            callback();
          });
        },
        //删除多余数据
        function (callback) {
          DAL_Factory.RedisRoom.Room_GiftFloat.Del(Value.RoomID, function () {
            callback();
          });
        }
      ], function (retValue) {
        if (retValue) {
          callback(retValue);
          return;
        }
        callback(KOC.ReturnValue.New({
          returnObject: _Data
        }));
      });
    },
    //endregion
    //region RedisRoom_GiftHeadline:礼物头条维护
    RedisRoom_GiftHeadline: function (Value, callback) {
      Value = KOC.Lodash.extend({
        User_ID: -1,
        User_NickName: null,
        Anchor_ID: -1,
        Anchor_NickName: null,
        GiftNum: 0,
        GiftAmt: 0,
        GiftInfo: null
      }, Value);
      if (!Value.GiftInfo) {
        callback(KOC.ReturnValue.New({
          hasError: true,
          message: "参数错误[GiftInfo]"
        }));
        return;
      }
      if (Value.GiftInfo.IsHeadline === false) {
        callback(KOC.ReturnValue.New());
        return;
      }
      Value.User_ID = KOC.StringUtils.ToIntPositive(Value.User_ID);
      Value.Anchor_ID = KOC.StringUtils.ToIntPositive(Value.Anchor_ID);
      Value.GiftNum = KOC.StringUtils.ToIntPositive(Value.GiftNum);
      Value.GiftAmt = KOC.StringUtils.ToIntPositive(Value.GiftAmt);
      if (Value.User_ID <= 0) {
        callback(KOC.ReturnValue.New({
          hasError: true,
          message: "参数错误[User_ID]"
        }));
        return;
      }
      if (Value.Anchor_ID <= 0) {
        callback(KOC.ReturnValue.New({
          hasError: true,
          message: "参数错误[Anchor_ID]"
        }));
        return;
      }
      if (Value.GiftNum <= 0) {
        callback(KOC.ReturnValue.New({
          hasError: true,
          message: "参数错误[GiftNum]"
        }));
        return;
      }
      if (Value.GiftAmt < 0) {
        callback(KOC.ReturnValue.New({
          hasError: true,
          message: "参数错误[GiftAmt]"
        }));
        return;
      }
      //读取头条设置
      Value.Settings = CommonUtils.Commodity.Gift.Headline;
      if (Value.GiftAmt < Value.Settings.TriggerAmt) {
        callback(KOC.ReturnValue.New());
        return;
      }
      var RedisMulti = null;
      KOC.Async.series([
        //监听GiftHeadline
        function (callback) {
          DAL_Factory.RedisRoom.GiftHeadline.Watch(function (retValue) {
            if (retValue.hasError) {
              callback(retValue);
              return;
            }
            callback();
          });
        },
        //读取GiftHeadline
        function (callback) {
          DAL_Factory.RedisRoom.GiftHeadline.Get(function (retValue) {
            if (retValue.hasError) {
              callback(retValue);
              return;
            }
            Value.Board = !retValue.returnObject
              || KOC.Moment().diff(retValue.returnObject.CreateDate, "seconds") > Value.Settings.GuardTime * 60
              || Value.GiftAmt > retValue.returnObject.GiftAmt;
            callback();
          });
        },
        //取消监听GiftHeadline
        function (callback) {
          if (Value.Board) {
            callback();
            return;
          }
          KOC.RedisHelper.Unwatch(Config.Redis.DB.Room);
          callback();
        },
        //开启事务
        function (callback) {
          if (!Value.Board) {
            callback();
            return;
          }
          var retValue = KOC.RedisHelper.Multi(Config.Redis.DB.Room);
          if (retValue.hasError) {
            callback(retValue);
            return;
          }
          RedisMulti = retValue.returnObject;
          callback();
        },
        //写入GiftHeadline
        function (callback) {
          if (!Value.Board) {
            callback();
            return;
          }
          DAL_Factory.RedisRoom.GiftHeadline.Set(RedisMulti, {
            User_ID: Value.User_ID,
            User_NickName: Value.User_NickName,
            Anchor_ID: Value.Anchor_ID,
            Anchor_NickName: Value.Anchor_NickName,
            GiftNum: Value.GiftNum,
            GiftAmt: Value.GiftAmt,
            GiftInfo: Value.GiftInfo,
            GuardTime: Value.Settings.GuardTime
          }, function (retValue) {
            if (retValue.hasError) {
              callback(retValue);
              return;
            }
            callback();
          });
        },
        //提交事务
        function (callback) {
          if (!Value.Board) {
            callback();
            return;
          }
          KOC.RedisHelper.Exec(RedisMulti, function (retValue) {
            if (retValue.hasError) {
              RedisMulti = null;
              callback(retValue);
              return;
            }
            callback();
          });
        },
        //读取头条信息
        function (callback) {
          if (!Value.Board) {
            callback();
            return;
          }
          DAL_Factory.RedisRoom.GiftHeadline.Get(function (retValue) {
            if (retValue.hasError) {
              callback(retValue);
              return;
            }
            Value.GiftHeadline = retValue.returnObject;
            callback();
          });
        }
      ], function (retValue) {
        if (retValue) {
          //撤销事务
          KOC.RedisHelper.Discard(RedisMulti);
          callback(retValue);
          return;
        }
        callback(KOC.ReturnValue.New({
          returnObject: Value.Board ? Value.GiftHeadline : null
        }));
      });
    },
    //endregion
    //region RedisRoom_Horn:喇叭购买
    RedisRoom_Horn: function (Value, callback) {
      Value = KOC.Lodash.extend({
        PurchaseMode: null, //购买模式 0:先使用包裹再购买 1:只购买 2:只使用包裹
        User_ID: null,
        User_ID_Anchor: null,
        Mode: null,
        Message: null,
        Create_IP: null
      }, Value);
      var RedisMulti = null;
      KOC.Async.series([
        //读取房间用户信息(购买人)
        function (callback) {
          DAL_Factory.Business.RedisRoom_RoomUserInfo({
            RoomID: Value.User_ID_Anchor,
            User_ID: Value.User_ID
          }, function (retValue) {
            if (retValue.hasError) {
              callback(retValue);
              return;
            }
            Value.RoomUserInfo = retValue.returnObject;
            callback();
          });
        },
        //喇叭购买(mysql)
        function (callback) {
          DAL_Factory.Business.User_HornPurchase({
            PurchaseMode: Value.PurchaseMode,
            User_ID: Value.User_ID,
            User_ID_Anchor: Value.User_ID_Anchor,
            Mode: Value.Mode,
            Message: Value.Message,
            Create_IP: Value.Create_IP
          }, function (retValue) {
            if (retValue.hasError) {
              callback(retValue);
              return;
            }
            Value.PurchaseMode = retValue.returnObject.PurchaseMode;
            Value.Order_Amt = retValue.returnObject.Order_Amt;
            Value.User_ID = retValue.returnObject.User_ID;
            Value.User_ID_Anchor = retValue.returnObject.User_ID_Anchor;
            Value.User_Pomelo = retValue.returnObject.User_Pomelo;
            Value.User_EXP = retValue.returnObject.User_EXP;
            Value.User_Coin = retValue.returnObject.User_Coin;
            Value.Anchor_Beans = retValue.returnObject.Anchor_Beans;
            Value.Anchor_Pomelo = retValue.returnObject.Anchor_Pomelo;
            Value.Anchor_EXP = retValue.returnObject.Anchor_EXP;
            Value.Anchor_Fans = retValue.returnObject.Anchor_Fans;
            Value.Anchor_Attention = retValue.returnObject.Anchor_Attention;
            Value.HornInfo = retValue.returnObject.HornInfo;
            callback();
          });
        },
        //开启事务
        function (callback) {
          var retValue = KOC.RedisHelper.Multi(Config.Redis.DB.Room);
          if (retValue.hasError) {
            callback(retValue);
            return;
          }
          RedisMulti = retValue.returnObject;
          callback();
        },
        //更新用户信息
        function (callback) {
          DAL_Factory.RedisRoom.UserInfo.Update(RedisMulti, {
            User_ID: Value.User_ID,
            Pomelo: Value.User_Pomelo,
            EXP: Value.User_EXP,
            Coin: Value.User_Coin
          }, function (retValue) {
            if (retValue.hasError) {
              callback(retValue);
              return;
            }
            callback();
          });
        },
        //更新房间艺人信息
        function (callback) {
          DAL_Factory.RedisRoom.Room_AnchorInfo.Update(RedisMulti, {
            RoomID: Value.User_ID_Anchor,
            Beans: Value.Anchor_Beans,
            Pomelo: Value.Anchor_Pomelo,
            EXP: Value.Anchor_EXP,
            Fans: Value.Anchor_Fans,
            Attention: Value.Anchor_Attention
          }, function (retValue) {
            if (retValue.hasError) {
              callback(retValue);
              return;
            }
            callback();
          });
        },
        //提交事务
        function (callback) {
          KOC.RedisHelper.Exec(RedisMulti, function (retValue) {
            if (retValue.hasError) {
              RedisMulti = null;
              callback(retValue);
              return;
            }
            callback();
          });
        },
        //取得房间用户信息
        function (callback) {
          DAL_Factory.Business.RedisRoom_RoomUserInfo({
            RoomID: Value.User_ID_Anchor,
            User_ID: Value.User_ID
          }, function (retValue) {
            if (retValue.hasError) {
              callback(retValue);
              return;
            }
            Value.UserUpgrade = retValue.returnObject.Level != Value.RoomUserInfo.Level;
            Value.RoomUserInfo = retValue.returnObject;
            callback();
          });
        },
        //取得房间艺人信息
        function (callback) {
          DAL_Factory.RedisRoom.Room_AnchorInfo.Get(Value.User_ID_Anchor, function (retValue) {
            if (retValue.hasError) {
              callback(retValue);
              return;
            }
            Value.RoomAnchorInfo = retValue.returnObject;
            callback();
          });
        },
        //取得用户包裹信息
        function (callback) {
          if (Value.Guest) {
            Value.UserPackage = [];
            callback();
            return;
          }
          DAL_Factory.User.User_Package.List(Value.User_ID, function (retValue) {
            if (retValue.hasError) {
              callback(retValue);
              return;
            }
            Value.UserPackage = retValue.returnObject;
            callback();
          });
        }
      ], function (retValue) {
        if (retValue) {
          //撤销事务
          KOC.RedisHelper.Discard(RedisMulti);
          callback(retValue);
          return;
        }
        callback(KOC.ReturnValue.New({
          returnObject: {
            Order_Amt: Value.Order_Amt,
            UserUpgrade: Value.UserUpgrade,
            RoomAnchorInfo: Value.RoomAnchorInfo,
            RoomUserInfo: Value.RoomUserInfo,
            UserPackage: Value.UserPackage,
            HornMessage: Value.Message,
            HornInfo: Value.HornInfo,
            CreateDate: new Date()
          }
        }));
      });
    },
    //endregion
    //region RedisRoom_PomeloGet:星星领取
    RedisRoom_PomeloGet: function (Value, callback) {
      Value = KOC.Lodash.extend({
        RoomID: null,
        User_ID: null
      }, Value);
      Value.RoomID = KOC.StringUtils.ToIntPositive(Value.RoomID);
      if (Value.RoomID <= 0) {
        callback(KOC.ReturnValue.New({
          hasError: true,
          message: "参数错误[RoomID]"
        }));
        return;
      }
      Value.User_ID = KOC.StringUtils.ToIntPositive(Value.User_ID);
      if (Value.User_ID <= 0) {
        callback(KOC.ReturnValue.New({
          hasError: true,
          message: "参数错误[User_ID]"
        }));
        return;
      }
      var RedisMulti = null;
      KOC.Async.series([
        //领取星星(mysql)
        function (callback) {
          DAL_Factory.Business.User_PomeloGet({
            User_ID: Value.User_ID
          }, function (retValue) {
            if (retValue.hasError) {
              callback(retValue);
              return;
            }
            Value.User_ID = retValue.returnObject.User_ID;
            Value.Pomelo = retValue.returnObject.Pomelo;
            Value.MAXToday = retValue.returnObject.MAXToday;
            Value.NumToday = retValue.returnObject.NumToday;
            callback();
          });
        },
        //开启事务
        function (callback) {
          var retValue = KOC.RedisHelper.Multi(Config.Redis.DB.Room);
          if (retValue.hasError) {
            callback(retValue);
            return;
          }
          RedisMulti = retValue.returnObject;
          callback();
        },
        //更新用户星星数量
        function (callback) {
          DAL_Factory.RedisRoom.UserInfo.Update(RedisMulti, {
            User_ID: Value.User_ID,
            Pomelo: Value.Pomelo
          }, function (retValue) {
            if (retValue.hasError) {
              callback(retValue);
              return;
            }
            callback();
          });
        },
        //提交事务
        function (callback) {
          KOC.RedisHelper.Exec(RedisMulti, function (retValue) {
            if (retValue.hasError) {
              RedisMulti = null;
              callback(retValue);
              return;
            }
            callback();
          });
        },
        //取得房间用户信息
        function (callback) {
          DAL_Factory.Business.RedisRoom_RoomUserInfo({
            RoomID: Value.RoomID,
            User_ID: Value.User_ID
          }, function (retValue) {
            if (retValue.hasError) {
              callback(retValue);
              return;
            }
            Value.RoomUserInfo = retValue.returnObject;
            callback();
          });
        }
      ], function (retValue) {
        if (retValue) {
          //撤销事务
          KOC.RedisHelper.Discard(RedisMulti);
          callback(retValue);
          return;
        }
        callback(KOC.ReturnValue.New({
          returnObject: Value.RoomUserInfo
        }));
      });
    },
    //endregion
    //region RedisRoom_PomeloPresent:星星赠送
    RedisRoom_PomeloPresent: function (Value, callback) {
      Value = KOC.Lodash.extend({
        RoomID: null,
        User_ID: null,
        Num: null,
        Create_IP: null
      }, Value);
      Value.RoomID = KOC.StringUtils.ToIntPositive(Value.RoomID);
      if (Value.RoomID <= 0) {
        callback(KOC.ReturnValue.New({
          hasError: true,
          message: "参数错误[RoomID]"
        }));
        return;
      }
      Value.User_ID = KOC.StringUtils.ToIntPositive(Value.User_ID);
      if (Value.User_ID <= 0) {
        callback(KOC.ReturnValue.New({
          hasError: true,
          message: "参数错误[User_ID]"
        }));
        return;
      }
      Value.Num = KOC.StringUtils.ToIntPositive(Value.Num);
      if (Value.Num <= 0) {
        callback(KOC.ReturnValue.New({
          hasError: true,
          message: "参数错误[Num]"
        }));
        return;
      }
      var RedisMulti = null;
      KOC.Async.series([
        //赠送星星(mysql)
        function (callback) {
          DAL_Factory.Business.User_PomeloPresent({
            User_ID: Value.User_ID,
            User_ID_Anchor: Value.RoomID,
            Num: Value.Num,
            Create_IP: Value.Create_IP
          }, function (retValue) {
            if (retValue.hasError) {
              callback(retValue);
              return;
            }
            Value.RoomID = retValue.returnObject.User_ID_Anchor;
            Value.User_ID = retValue.returnObject.User_ID;
            Value.Num = retValue.returnObject.Num;
            Value.EXP = retValue.returnObject.EXP;
            Value.EXP_Anchor = retValue.returnObject.EXP_Anchor;
            Value.User_Pomelo = retValue.returnObject.User_Pomelo;
            Value.User_EXP = retValue.returnObject.User_EXP;
            Value.Anchor_Fans = retValue.returnObject.Anchor_Fans;
            Value.Anchor_Attention = retValue.returnObject.Anchor_Attention;
            Value.Anchor_Pomelo = retValue.returnObject.Anchor_Pomelo;
            Value.Anchor_EXP = retValue.returnObject.Anchor_EXP;
            Value.Live_Order_No = retValue.returnObject.Live_Order_No;
            callback();
          });
        },
        //读取房间用户信息
        function (callback) {
          DAL_Factory.Business.RedisRoom_RoomUserInfo({
            RoomID: Value.RoomID,
            User_ID: Value.User_ID
          }, function (retValue) {
            if (retValue.hasError) {
              callback(retValue);
              return;
            }
            Value.RoomUserInfo = retValue.returnObject;
            callback();
          });
        },
        //开启事务
        function (callback) {
          var retValue = KOC.RedisHelper.Multi(Config.Redis.DB.Room);
          if (retValue.hasError) {
            callback(retValue);
            return;
          }
          RedisMulti = retValue.returnObject;
          callback();
        },
        //更新用户信息
        function (callback) {
          DAL_Factory.RedisRoom.UserInfo.Update(RedisMulti, {
            User_ID: Value.User_ID,
            Pomelo: Value.User_Pomelo,
            EXP: Value.User_EXP
          }, function (retValue) {
            if (retValue.hasError) {
              callback(retValue);
              return;
            }
            callback();
          });
        },
        //更新房间艺人信息
        function (callback) {
          DAL_Factory.RedisRoom.Room_AnchorInfo.Update(RedisMulti, {
            RoomID: Value.RoomID,
            Pomelo: Value.Anchor_Pomelo,
            EXP: Value.Anchor_EXP,
            Fans: Value.Anchor_Fans,
            Attention: Value.Anchor_Attention
          }, function (retValue) {
            if (retValue.hasError) {
              callback(retValue);
              return;
            }
            callback();
          });
        },
        //提交事务
        function (callback) {
          KOC.RedisHelper.Exec(RedisMulti, function (retValue) {
            if (retValue.hasError) {
              RedisMulti = null;
              callback(retValue);
              return;
            }
            callback();
          });
        },
        //取得房间艺人信息
        function (callback) {
          DAL_Factory.RedisRoom.Room_AnchorInfo.Get(Value.RoomID, function (retValue) {
            if (retValue.hasError) {
              callback(retValue);
              return;
            }
            Value.RoomAnchorInfo = retValue.returnObject;
            callback();
          });
        },
        //取得房间用户信息
        function (callback) {
          DAL_Factory.Business.RedisRoom_RoomUserInfo({
            RoomID: Value.RoomID,
            User_ID: Value.User_ID
          }, function (retValue) {
            if (retValue.hasError) {
              callback(retValue);
              return;
            }
            Value.UserUpgrade = retValue.returnObject.Level != Value.RoomUserInfo.Level;
            Value.RoomUserInfo = retValue.returnObject;
            callback();
          });
        }
      ], function (retValue) {
        if (retValue) {
          //撤销事务
          KOC.RedisHelper.Discard(RedisMulti);
          callback(retValue);
          return;
        }
        callback(KOC.ReturnValue.New({
          returnObject: {
            Num: Value.Num,
            EXP: Value.EXP * Value.Num,
            UserUpgrade: Value.UserUpgrade,
            RoomAnchorInfo: Value.RoomAnchorInfo,
            RoomUserInfo: Value.RoomUserInfo,
            CreateDate: new Date()
          }
        }));
      });
    },
    //endregion
    //region RedisRoom_AdminSet:管理员设置
    RedisRoom_AdminSet: function (Value, callback) {
      Value = KOC.Lodash.extend({
        RoomID: null,
        User_ID: null,
        RoomAdmin: null
      }, Value);
      Value.RoomID = KOC.StringUtils.ToIntPositive(Value.RoomID);
      if (Value.RoomID <= 0) {
        callback(KOC.ReturnValue.New({
          hasError: true,
          message: "参数错误[RoomID]"
        }));
        return;
      }
      Value.User_ID = KOC.StringUtils.ToIntPositive(Value.User_ID);
      if (Value.User_ID <= 0) {
        callback(KOC.ReturnValue.New({
          hasError: true,
          message: "参数错误[User_ID]"
        }));
        return;
      }
      if (Value.RoomID == Value.User_ID) {
        callback(KOC.ReturnValue.New({
          hasError: true,
          message: "您不能设置自己为房间管理员"
        }));
        return;
      }
      var RedisMulti = null;
      KOC.Async.series([
        //设置管理员(mysql)
        function (callback) {
          DAL_Factory.Business.User_AnchorAdminSet({
            User_ID: Value.User_ID,
            User_ID_Anchor: Value.RoomID,
            Cancel: !Value.RoomAdmin
          }, function (retValue) {
            if (retValue.hasError) {
              callback(retValue);
              return;
            }
            callback();
          });
        },
        //开启事务
        function (callback) {
          var retValue = KOC.RedisHelper.Multi(Config.Redis.DB.Room);
          if (retValue.hasError) {
            callback(retValue);
            return;
          }
          RedisMulti = retValue.returnObject;
          callback();
        },
        //修改房间用户信息
        function (callback) {
          DAL_Factory.RedisRoom.Room_UserInfo.Update(RedisMulti, {
            RoomID: Value.RoomID,
            User_ID: Value.User_ID,
            Admin: Value.RoomAdmin
          }, function (retValue) {
            if (retValue.hasError) {
              callback(retValue);
              return;
            }
            callback();
          });
        },
        //提交事务
        function (callback) {
          KOC.RedisHelper.Exec(RedisMulti, function (retValue) {
            if (retValue.hasError) {
              RedisMulti = null;
              callback(retValue);
              return;
            }
            callback();
          });
        },
        //取得房间用户信息
        function (callback) {
          DAL_Factory.Business.RedisRoom_RoomUserInfo({
            RoomID: Value.RoomID,
            User_ID: Value.User_ID
          }, function (retValue) {
            if (!retValue.hasError) {
              Value.RoomUserInfo = retValue.returnObject;
            }
            callback();
          });
        }
      ], function (retValue) {
        if (retValue) {
          //撤销事务
          KOC.RedisHelper.Discard(RedisMulti);
          callback(retValue);
          return;
        }
        callback(KOC.ReturnValue.New({
          returnObject: {
            RoomUserInfo: Value.RoomUserInfo,
            CreateDate: new Date()
          }
        }));
      });
    },
    //endregion
    //region RedisRoom_BlackSet:黑名单设置
    RedisRoom_BlackSet: function (Value, callback) {
      Value = KOC.Lodash.extend({
        RoomID: null, //房间ID
        User_ID: null, //被操作用户ID
        User_ID_Admin: null, //管理员操作用户
        Type: null, //操作类型 （INT）约定：1：禁言，2：踢人，3：取消禁言，4：取消踢人
        Mode: null, //禁言或踢人,的类型，["NEVER", "YEAR", "MONTH", "WEEK", "DAY", "HOUR", "MINUTE"]
        Value: null //禁言或踢人的时间值
      }, Value);
      Value.RoomID = KOC.StringUtils.ToIntPositive(Value.RoomID);
      if (Value.RoomID <= 0) {
        callback(KOC.ReturnValue.New({
          hasError: true,
          message: "参数错误[RoomID]"
        }));
        return;
      }
      Value.User_ID = KOC.StringUtils.ToIntPositive(Value.User_ID);
      if (Value.User_ID <= 0) {
        callback(KOC.ReturnValue.New({
          hasError: true,
          message: "参数错误[User_ID]"
        }));
        return;
      }
      Value.User_ID_Admin = KOC.StringUtils.ToIntPositive(Value.User_ID_Admin);
      if (Value.User_ID_Admin <= 0) {
        callback(KOC.ReturnValue.New({
          hasError: true,
          message: "参数错误[User_ID_Admin]"
        }));
        return;
      }
      var RedisMulti = null;
      KOC.Async.series([
        //读取房间信息
        function (callback) {
          if (Value.Type != 2) {
            callback();
            return;
          }
          DAL_Factory.RedisRoom.RoomInfo.Get(Value.RoomID, function (retValue) {
            if (retValue.hasError) {
              callback(retValue);
              return;
            }
            Value.RoomInfo = retValue.returnObject;
            callback();
          });
        },
        //读取房间用户信息(操作人)
        function (callback) {
          DAL_Factory.Business.RedisRoom_RoomUserInfo({
            RoomID: Value.RoomID,
            User_ID: Value.User_ID_Admin
          }, function (retValue) {
            if (retValue.hasError) {
              callback(retValue);
              return;
            }
            Value.RoomUserInfo_Admin = retValue.returnObject;
            callback();
          });
        },
        //黑名单设置(mysql)
        function (callback) {
          DAL_Factory.Business.User_AnchorBlackSet({
            User_ID: Value.User_ID,
            User_ID_Admin: Value.User_ID_Admin,
            User_ID_Anchor: Value.RoomID,
            Type: Value.Type,
            Mode: Value.Mode,
            Value: Value.Value
          }, function (retValue) {
            if (retValue.hasError) {
              callback(retValue);
              return;
            }
            Value.RoomUserBlackInfo = retValue.returnObject;
            callback();
          });
        },
        //结束直播(连麦)
        function (callback) {
          if (!Value.RoomInfo) {
            callback();
            return;
          }
          if (Value.RoomInfo.Live_UserID_LinkAnchor == Value.User_ID) {
            Value.RoomInfo_LiveSocketID = Value.RoomInfo.Live_SocketID_LinkAnchor;
          }
          if (Value.RoomInfo.Live_UserID_LinkUser == Value.User_ID) {
            Value.RoomInfo_LiveSocketID = Value.RoomInfo.Live_SocketID_LinkUser;
          }
          if (!Value.RoomInfo_LiveSocketID) {
            Value.RoomInfo = null;
            callback();
            return;
          }
          DAL_Factory.Business.RedisRoom_LiveEnd({
            RoomID: Value.RoomID,
            User_ID: Value.User_ID,
            SocketID: Value.RoomInfo_LiveSocketID
          }, function (retValue) {
            if (retValue.hasError) {
              callback();
              return;
            }
            Value.RoomInfo = retValue.returnObject.RoomInfo;
            callback();
          });
        },
        //开启事务
        function (callback) {
          var retValue = KOC.RedisHelper.Multi(Config.Redis.DB.Room);
          if (retValue.hasError) {
            callback(retValue);
            return;
          }
          RedisMulti = retValue.returnObject;
          callback();
        },
        //修改房间用户信息
        function (callback) {
          DAL_Factory.RedisRoom.Room_UserInfo.Update(RedisMulti, {
            RoomID: Value.RoomID,
            User_ID: Value.User_ID,
            Black: Value.RoomUserBlackInfo.Shutup,
            Black_Shutup_Expire: Value.RoomUserBlackInfo.Shutup_Expire
          }, function (retValue) {
            if (retValue.hasError) {
              callback(retValue);
              return;
            }
            callback();
          });
        },
        //提交事务
        function (callback) {
          KOC.RedisHelper.Exec(RedisMulti, function (retValue) {
            if (retValue.hasError) {
              RedisMulti = null;
              callback(retValue);
              return;
            }
            callback();
          });
        },
        //取得房间用户信息
        function (callback) {
          DAL_Factory.Business.RedisRoom_RoomUserInfo({
            RoomID: Value.RoomID,
            User_ID: Value.User_ID
          }, function (retValue) {
            if (!retValue.hasError) {
              Value.RoomUserInfo = retValue.returnObject;
            }
            callback();
          });
        },
        //取得用户socket列表
        function (callback) {
          if (!Value.RoomUserBlackInfo.Join) {
            callback();
            return;
          }
          DAL_Factory.RedisRoom.Room_UserInfo_Socket.Get(Value.RoomID, Value.User_ID, function (retValue) {
            if (!retValue.hasError) {
              Value.RoomUserSocket = retValue.returnObject;
            }
            callback();
          });
        },
        //开启事务
        function (callback) {
          var retValue = KOC.RedisHelper.Multi(Config.Redis.DB.Room);
          if (retValue.hasError) {
            callback(retValue);
            return;
          }
          RedisMulti = retValue.returnObject;
          callback();
        },
        //删除用户socket
        function (callback) {
          if (!Value.RoomUserBlackInfo.Join) {
            callback();
            return;
          }
          DAL_Factory.RedisRoom.Room_UserInfo_Socket.Del(RedisMulti, Value.RoomID, Value.User_ID, function (retValue) {
            if (retValue.hasError) {
              callback(retValue);
              return;
            }
            callback();
          });
        },
        //删除房间用户信息
        function (callback) {
          if (!Value.RoomUserBlackInfo.Join) {
            callback();
            return;
          }
          DAL_Factory.RedisRoom.Room_UserInfo.Del(RedisMulti, Value.RoomID, Value.User_ID, function (retValue) {
            if (retValue.hasError) {
              callback(retValue);
              return;
            }
            callback();
          });
        },
        //删除房间用户列表
        function (callback) {
          if (!Value.RoomUserBlackInfo.Join) {
            callback();
            return;
          }
          DAL_Factory.RedisRoom.Room_UserList.Remove(RedisMulti, Value.RoomID, Value.User_ID, function (retValue) {
            if (retValue.hasError) {
              callback(retValue);
              return;
            }
            callback();
          });
        },
        //删除用户信息
        function (callback) {
          if (!Value.RoomUserBlackInfo.Join) {
            callback();
            return;
          }
          callback();
        }
      ], function (retValue) {
        if (retValue) {
          //撤销事务
          KOC.RedisHelper.Discard(RedisMulti);
          callback(retValue);
          return;
        }
        callback(KOC.ReturnValue.New({
          returnObject: {
            Type: Value.Type,
            RoomInfo: Value.RoomInfo,
            RoomUserInfo_Admin: Value.RoomUserInfo_Admin,
            RoomUserInfo: Value.RoomUserInfo,
            RoomUserSocket: Value.RoomUserSocket,
            RoomUserBlackInfo: Value.RoomUserBlackInfo,
            CreateDate: new Date()
          }
        }));
      });
    },
    //endregion
    //region RedisRoom_BlockSet:冻结房间
    RedisRoom_BlockSet: function (Value, callback) {
      Value = KOC.Lodash.extend({
        RoomID: null, //房间ID
        Block: null, //操作方式 true:冻结 false:解冻
        AdminID: null,
        Operation: null,//操作描述
        Data: null,
        Create_IP: null
      }, Value);
      var RedisMulti = null;
      KOC.Async.series([
        //冻结解冻房间
        function (callback) {
          DAL_Factory.User.User_Anchor.Update_Status({
            User_ID: Value.RoomID,
            Status: Value.Block ? 1 : 0
          }, function (retValue) {
            if (retValue.hasError) {
              callback(retValue);
              return;
            }
            callback();
          });
        },
        //查询管理员信息
        function (callback) {
          DAL_Factory.User.User_Admin.Info(Value.AdminID, function (retValue) {
            if (retValue.hasError) {
              callback(retValue);
              return;
            }
            if (!retValue.returnObject) {
              retValue.hasError = true;
              retValue.message = '没有该管理员信息';
              return;
            }
            Value.RealName = retValue.returnObject.RealName;
            Value.Phone = retValue.returnObject.Phone;
            callback();
          });
        },
        //查看艺人信息
        function (callback) {
          DAL_Factory.User.User_Anchor.Info(Value.RoomID, function (retValue) {
            if (retValue.hasError) {
              callback(retValue);
              return;
            }
            if (!retValue.returnObject) {
              retValue.hasError = true;
              retValue.message = "无此艺人信息,用户不是艺人身份";
              callback(retValue);
              return;
            }
            Value.AnchorLive = retValue.returnObject.Live;
            callback();
          });
        },
        //开启事务
        function (callback) {
          if (!Value.Block) {
            callback();
            return;
          }
          var retValue = KOC.RedisHelper.Multi(Config.Redis.DB.Room);
          if (retValue.hasError) {
            callback(retValue);
            return;
          }
          RedisMulti = retValue.returnObject;
          callback();
        },
        //结束直播(mysql)
        function (callback) {
          if (!Value.AnchorLive) {
            callback();
            return;
          }
          DAL_Factory.Business.User_AnchorLiveEnd(Value.RoomID, function (retValue) {
            if (retValue.hasError) {
              callback(retValue);
              return;
            }
            callback();
          });
        },
        //结束直播
        function (callback) {
          if (!Value.Block) {
            callback();
            return;
          }
          DAL_Factory.RedisRoom.RoomInfo.Set_LiveEnd(RedisMulti, Value.RoomID, function (retValue) {
            if (retValue.hasError) {
              callback(retValue);
              return;
            }
            callback();
          });
        },
        //提交事务
        function (callback) {
          if (!Value.Block) {
            callback();
            return;
          }
          KOC.RedisHelper.Exec(RedisMulti, function (retValue) {
            if (retValue.hasError) {
              RedisMulti = null;
              callback(retValue);
              return;
            }
            callback();
          });
        },
        //读取房间信息
        function (callback) {
          DAL_Factory.RedisRoom.RoomInfo.Get(Value.RoomID, function (retValue) {
            if (!retValue.hasError) {
              Value.RoomInfo = retValue.returnObject;
            }
            callback();
          });
        }
      ], function (retValue) {
        if (retValue) {
          //撤销事务
          KOC.RedisHelper.Discard(RedisMulti);
          callback(retValue);
          return;
        }
        callback(KOC.ReturnValue.New({
          returnObject: Value.RoomInfo
        }));
      });
    },
    //endregion
    //region RedisRoom_Lottery:转盘抽奖
    RedisRoom_Lottery: function (Value, callback) {
      Value = KOC.Lodash.extend({
        User_ID: null,//用户ID
        User_ID_Anchor: null,//直播间ID
        Lottery_ID: null,//抽奖ID
        Create_IP: null
      }, Value);
      var RedisMulti = null;
      KOC.Async.series([
        //取得房间用户信息
        function (callback) {
          DAL_Factory.Business.RedisRoom_RoomUserInfo({
            RoomID: Value.User_ID_Anchor,
            User_ID: Value.User_ID
          }, function (retValue) {
            if (retValue.hasError) {
              callback(retValue);
              return;
            }
            Value.RoomUserInfo = retValue.returnObject;
            callback();
          });
        },
        //进行抽奖
        function (callback) {
          DAL_Factory.Business.User_Lottery({
            User_ID: Value.User_ID,//用户ID
            User_ID_Anchor: Value.User_ID_Anchor,//直播间ID
            Lottery_ID: Value.Lottery_ID,//抽奖ID
            Create_IP: Value.Create_IP
          }, function (retValue) {
            if (retValue.hasError) {
              callback(retValue);
              return;
            }
            Value.Pomelo = retValue.returnObject.Pomelo;
            Value.EXP = retValue.returnObject.EXP;
            Value.Coin = retValue.returnObject.Coin;
            Value.LotteryInfo = retValue.returnObject.LotteryInfo;
            Value.LotteryWinningList = retValue.returnObject.LotteryWinningList;
            callback();
          });
        },
        //开启事务
        function (callback) {
          var retValue = KOC.RedisHelper.Multi(Config.Redis.DB.Room);
          if (retValue.hasError) {
            callback(retValue);
            return;
          }
          RedisMulti = retValue.returnObject;
          callback();
        },
        //更新用户信息
        function (callback) {
          DAL_Factory.RedisRoom.UserInfo.Update(RedisMulti, {
            User_ID: Value.User_ID,
            Pomelo: Value.Pomelo,
            EXP: Value.EXP,
            Coin: Value.Coin
          }, function (retValue) {
            if (retValue.hasError) {
              callback(retValue);
              return;
            }
            callback();
          });
        },
        //提交事务
        function (callback) {
          KOC.RedisHelper.Exec(RedisMulti, function (retValue) {
            if (retValue.hasError) {
              RedisMulti = null;
              callback(retValue);
              return;
            }
            callback();
          });
        },
        //读取房间用户信息
        function (callback) {
          DAL_Factory.Business.RedisRoom_RoomUserInfo({
            RoomID: Value.User_ID_Anchor,
            User_ID: Value.User_ID
          }, function (retValue) {
            if (retValue.hasError) {
              callback(retValue);
              return;
            }
            Value.RoomUserInfo = retValue.returnObject;
            callback();
          });
        },
        //取得房间艺人信息
        function (callback) {
          DAL_Factory.RedisRoom.Room_AnchorInfo.Get(Value.User_ID_Anchor, function (retValue) {
            if (retValue.hasError) {
              callback(retValue);
              return;
            }
            Value.RoomAnchorInfo = retValue.returnObject;
            callback();
          });
        },
        //取得用户包裹信息
        function (callback) {
          DAL_Factory.User.User_Package.List(Value.User_ID, function (retValue) {
            if (retValue.hasError) {
              callback(retValue);
              return;
            }
            Value.UserPackage = retValue.returnObject;
            callback();
          });
        }
      ], function (retValue) {
        if (retValue) {
          callback(retValue);
          return;
        }
        callback(KOC.ReturnValue.New({
          returnObject: {
            RoomUserInfo: Value.RoomUserInfo,
            RoomAnchorInfo: Value.RoomAnchorInfo,
            UserPackage: Value.UserPackage,
            LotteryInfo: Value.LotteryInfo,
            LotteryWinningList: Value.LotteryWinningList
          }
        }));
      });
    },
    //endregion
    //region RedisRoom_WarningSet:艺人警告设置
    RedisRoom_WarningSet: function (Value, callback) {
      Value = KOC.Lodash.extend({
        User_ID_Admin: null,//管理员ID
        User_NickName_Admin: null,//操作人昵称
        User_RealName_Admin: null,//被操作艺人真实姓名
        User_ID: null,//用户ID
        Integral: null,//罚分
        Type: null,//类型
        Operation: null,//操作类型:-1-警告,1-结束直播,2-冻结房间
        Inform: null,//通知类型:-1-默认不通知,1-通知艺人自己,2-通知房间内所有用户,3-通知全服
        Remark: null,//说明
        Create_IP: null
      }, Value);
      Value.Operation = KOC.StringUtils.ToInt(Value.Operation, -1);
      Value.Inform = KOC.StringUtils.ToInt(Value.Inform, -1);
      Value.Type = KOC.StringUtils.ToString(Value.Type);
      Value.Remark = KOC.StringUtils.ToString(Value.Remark);
      KOC.Async.series([
        //读取房间信息
        function (callback) {
          DAL_Factory.RedisRoom.RoomInfo.Get(Value.User_ID, function (retValue) {
            if (retValue.hasError) {
              callback(retValue);
              return;
            }
            Value.AnchorLive = retValue.returnObject.Live;//艺人是否开播
            callback();
          });
        },
        //进行艺人罚分(mysql)
        function (callback) {
          DAL_Factory.Business.User_AnchorIntegralUpdate({
            User_ID_Admin: Value.User_ID_Admin,//管理员ID
            User_NickName_Admin: Value.User_NickName_Admin,//操作人昵称
            User_RealName_Admin: Value.User_RealName_Admin,//操作艺人真实姓名
            User_ID: Value.User_ID,//用户ID
            Integral: Value.Integral,//罚分
            Type: Value.Type,//类型
            Operation: Value.Operation,//操作类型:-1-警告,1-结束直播,2-冻结房间
            Inform: Value.Inform,//通知类型:-1-默认不通知,1-通知艺人自己,2-通知房间内所有用户,3-通知全服
            Remark: Value.Remark,//说明
            Create_IP: Value.Create_IP
          }, function (retValue) {
            if (retValue.hasError) {
              callback(retValue);
              return;
            }
            Value.Integral = retValue.returnObject.Integral;
            Value.Operation = retValue.returnObject.Operation;
            Value.Inform = retValue.returnObject.Inform;
            callback();
          });
        },
        //冻结房间(mysql)
        function (callback) {
          if (Value.Operation != 2) {
            callback();
            return;
          }
          DAL_Factory.User.User_Anchor.Update_Status({
            User_ID: Value.User_ID,
            Status: 1
          }, function (retValue) {
            if (retValue.hasError) {
              callback(retValue);
              return;
            }
            if (retValue.returnObject != 1) {
              retValue.message = "更新艺人状态信息出错，影响行(" + retValue.returnObject + ")";
              callback(retValue);
              return;
            }
            callback();
          });
        },
        //结束直播
        function (callback) {
          if (!Value.AnchorLive || (Value.Operation != 1 && Value.Operation != 2)) {
            Value.RoomInfo = null;
            callback();
            return;
          }
          DAL_Factory.Business.RedisRoom_LiveEnd({
            RoomID: Value.User_ID,
            IsAdmin: true
          }, function (retValue) {
            if (retValue.hasError) {
              callback(retValue);
              return;
            }
            Value.RoomInfo = retValue.returnObject;
            callback();
          });
        },
        //取得艺人Socket信息
        function (callback) {
          DAL_Factory.RedisRoom.Room_UserInfo_Socket.Get(Value.User_ID, Value.User_ID, function (retValue) {
            if (retValue.hasError) {
              callback(retValue);
              return;
            }
            Value.RoomAnchorSocket = retValue.returnObject;
            callback();
          });
        }
      ], function (retValue) {
        if (retValue) {
          callback(retValue);
          return;
        }
        callback(KOC.ReturnValue.New({
          returnObject: {
            Integral: Value.Integral,
            Operation: Value.Operation,
            Inform: Value.Inform,
            RoomAnchorSocket: Value.RoomAnchorSocket
          }
        }));
      });
    },
    //endregion
    //region RedisRoom_PoundEgg:砸蛋游戏
    RedisRoom_PoundEgg: function (Value, callback) {
      Value = KOC.Lodash.extend({
        User_ID: null,//用户ID
        User_ID_Anchor: null,//直播间ID
        PoundEgg_ID: null,//砸蛋ID
        Create_IP: null
      }, Value);
      var RedisMulti = null;
      KOC.Async.series([
        //取得房间用户信息
        function (callback) {
          DAL_Factory.Business.RedisRoom_RoomUserInfo({
            RoomID: Value.User_ID_Anchor,
            User_ID: Value.User_ID
          }, function (retValue) {
            if (retValue.hasError) {
              callback(retValue);
              return;
            }
            Value.RoomUserInfo = retValue.returnObject;
            callback();
          });
        },
        //进行砸蛋
        function (callback) {
          DAL_Factory.Business.User_PoundEgg({
            User_ID: Value.User_ID,//用户ID
            User_ID_Anchor: Value.User_ID_Anchor,//直播间ID
            PoundEgg_ID: Value.PoundEgg_ID,//砸蛋ID
            Create_IP: Value.Create_IP
          }, function (retValue) {
            if (retValue.hasError) {
              callback(retValue);
              return;
            }
            Value.Pomelo = retValue.returnObject.Pomelo;
            Value.EXP = retValue.returnObject.EXP;
            Value.Coin = retValue.returnObject.Coin;
            Value.PoundEggInfo = retValue.returnObject.PoundEggInfo;
            Value.PoundEggWinningList = retValue.returnObject.PoundEggWinningList;
            callback();
          });
        },
        //开启事务
        function (callback) {
          var retValue = KOC.RedisHelper.Multi(Config.Redis.DB.Room);
          if (retValue.hasError) {
            callback(retValue);
            return;
          }
          RedisMulti = retValue.returnObject;
          callback();
        },
        //更新用户信息
        function (callback) {
          DAL_Factory.RedisRoom.UserInfo.Update(RedisMulti, {
            User_ID: Value.User_ID,
            Pomelo: Value.Pomelo,
            EXP: Value.EXP,
            Coin: Value.Coin
          }, function (retValue) {
            if (retValue.hasError) {
              callback(retValue);
              return;
            }
            callback();
          });
        },
        //提交事务
        function (callback) {
          KOC.RedisHelper.Exec(RedisMulti, function (retValue) {
            if (retValue.hasError) {
              RedisMulti = null;
              callback(retValue);
              return;
            }
            callback();
          });
        },
        //读取房间用户信息
        function (callback) {
          DAL_Factory.Business.RedisRoom_RoomUserInfo({
            RoomID: Value.User_ID_Anchor,
            User_ID: Value.User_ID
          }, function (retValue) {
            if (retValue.hasError) {
              callback(retValue);
              return;
            }
            Value.RoomUserInfo = retValue.returnObject;
            callback();
          });
        },
        //取得房间艺人信息
        function (callback) {
          DAL_Factory.RedisRoom.Room_AnchorInfo.Get(Value.User_ID_Anchor, function (retValue) {
            if (retValue.hasError) {
              callback(retValue);
              return;
            }
            Value.RoomAnchorInfo = retValue.returnObject;
            callback();
          });
        },
        //取得用户包裹信息
        function (callback) {
          DAL_Factory.User.User_Package.List(Value.User_ID, function (retValue) {
            if (retValue.hasError) {
              callback(retValue);
              return;
            }
            Value.UserPackage = retValue.returnObject;
            callback();
          });
        }
      ], function (retValue) {
        if (retValue) {
          callback(retValue);
          return;
        }
        callback(KOC.ReturnValue.New({
          returnObject: {
            RoomUserInfo: Value.RoomUserInfo,
            RoomAnchorInfo: Value.RoomAnchorInfo,
            UserPackage: Value.UserPackage,
            PoundEggInfo: Value.PoundEggInfo,
            PoundEggWinningList: Value.PoundEggWinningList
          }
        }));
      });
    }
    //endregion
    //endregion
  }
};
